diff options
-rw-r--r-- | engine/js/lib/ajax.js | 2 | ||||
-rw-r--r-- | engine/js/lib/elgglib.js | 16 | ||||
-rw-r--r-- | engine/js/tests/ElggLibTest.js | 18 | ||||
-rw-r--r-- | engine/lib/entities.php | 1 |
4 files changed, 24 insertions, 13 deletions
diff --git a/engine/js/lib/ajax.js b/engine/js/lib/ajax.js index bce0d31d3..184fd0da3 100644 --- a/engine/js/lib/ajax.js +++ b/engine/js/lib/ajax.js @@ -18,7 +18,7 @@ elgg.provide('elgg.ajax'); elgg.ajax = function(url, options) {
options = elgg.ajax.handleOptions(url, options);
- options.url = elgg.extendUrl(options.url);
+ options.url = elgg.normalize_url(options.url);
return $.ajax(options);
};
/**
diff --git a/engine/js/lib/elgglib.js b/engine/js/lib/elgglib.js index a91def2b9..32dbb1ec3 100644 --- a/engine/js/lib/elgglib.js +++ b/engine/js/lib/elgglib.js @@ -55,6 +55,10 @@ elgg.require = function(pkg) { * elgg.package = elgg.package || {};
* elgg.package.subpackage = elgg.package.subpackage || {};
* </pre>
+ *
+ * @example elgg.provide('elgg.config.translations')
+ *
+ * @param {string} pkg The package name.
*/
elgg.provide = function(pkg) {
elgg.assertTypeOf('string', pkg);
@@ -105,13 +109,15 @@ elgg.inherit = function(Child, Parent) { * @return {String} The extended url
* @private
*/
-elgg.extendUrl = function(url) {
+elgg.normalize_url = function(url) {
url = url || '';
- if(url.indexOf(elgg.config.wwwroot) == -1) {
- url = elgg.config.wwwroot + url;
+ elgg.assertTypeOf('string', url);
+
+ if(/(^(https?:)?\/\/)/.test(url)) {
+ return url;
}
- return url;
+ return elgg.config.wwwroot + url;
};
/**
@@ -177,5 +183,5 @@ elgg.register_error = function(errors, delay) { * @param {String} url The url to forward to
*/
elgg.forward = function(url) {
- location.href = elgg.extendUrl(url);
+ location.href = elgg.normalize_url(url);
};
\ No newline at end of file diff --git a/engine/js/tests/ElggLibTest.js b/engine/js/tests/ElggLibTest.js index ed4db24e1..035b60325 100644 --- a/engine/js/tests/ElggLibTest.js +++ b/engine/js/tests/ElggLibTest.js @@ -73,12 +73,16 @@ ElggLibTest.prototype.testInherit = function() { };
ElggLibTest.prototype.testExtendUrl = function() {
- var url;
- elgg.config.wwwroot = "http://www.elgg.org/";
+ elgg.config.wwwroot = "http://elgg.org/";
- url = '';
- assertEquals(elgg.config.wwwroot, elgg.extendUrl(url));
-
- url = 'pg/test';
- assertEquals('http://www.elgg.org/pg/test', elgg.extendUrl(url));
+ var inputs = [
+ [elgg.config.wwwroot, ''],
+ [elgg.config.wwwroot + 'pg/test', 'pg/test'],
+ ['http://google.com', 'http://google.com'],
+ ['//example.com', '//example.com'],
+ ];
+
+ for (var i in inputs) {
+ assertEquals(inputs[i][0], elgg.normalize_url(inputs[i][1]));
+ }
};
\ No newline at end of file diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 915939922..1c8db655b 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -629,6 +629,7 @@ function entity_row_to_elggstar($row) { } if (!$new_entity) { + //@todo Make this into a function switch ($row->type) { case 'object' : $new_entity = new ElggObject($row); |