aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/classes/ElggPriorityList.js7
-rw-r--r--js/lib/elgglib.js41
-rw-r--r--js/lib/hooks.js2
-rw-r--r--js/tests/ElggLanguagesTest.js2
-rw-r--r--js/tests/ElggLibTest.js37
-rw-r--r--js/tests/ElggPriorityListTest.js6
-rw-r--r--js/tests/ElggSecurityTest.js6
-rw-r--r--js/tests/README24
-rw-r--r--js/tests/jsTestDriver.conf5
9 files changed, 104 insertions, 26 deletions
diff --git a/js/classes/ElggPriorityList.js b/js/classes/ElggPriorityList.js
index 831342f21..b4cec5044 100644
--- a/js/classes/ElggPriorityList.js
+++ b/js/classes/ElggPriorityList.js
@@ -16,7 +16,10 @@ elgg.ElggPriorityList = function() {
* @return {Void}
*/
elgg.ElggPriorityList.prototype.insert = function(obj, opt_priority) {
- var priority = parseInt(opt_priority || 500, 10);
+ var priority = 500;
+ if (arguments.length == 2 && opt_priority != undefined) {
+ priority = parseInt(opt_priority, 10);
+ }
priority = Math.max(priority, 0);
@@ -31,7 +34,7 @@ elgg.ElggPriorityList.prototype.insert = function(obj, opt_priority) {
/**
* Iterates through each element in order.
*
-* Unlike every, this ignores the return value of the callback.
+ * Unlike every, this ignores the return value of the callback.
*
* @param {Function} callback The callback function to pass each element through. See
* Array.prototype.every() for details.
diff --git a/js/lib/elgglib.js b/js/lib/elgglib.js
index d963a62be..ca7914e7c 100644
--- a/js/lib/elgglib.js
+++ b/js/lib/elgglib.js
@@ -224,8 +224,8 @@ elgg.provide = function(pkg, opt_context) {
* child.foo('boo!'); // alert('boo!');
* </pre>
*
- * @param {Function} childCtor Child class.
- * @param {Function} parentCtor Parent class.
+ * @param {Function} Child Child class constructor.
+ * @param {Function} Parent Parent class constructor.
*/
elgg.inherit = function(Child, Parent) {
Child.prototype = new Parent();
@@ -250,8 +250,35 @@ elgg.normalize_url = function(url) {
url = url || '';
elgg.assertTypeOf('string', url);
- // jslint complains if you use /regexp/ shorthand here... ?!?!
- if ((new RegExp("^(https?:)?//", "i")).test(url)) {
+ validated = (function(url) {
+ url = elgg.parse_url(url);
+ if (url.scheme){
+ url.scheme = url.scheme.toLowerCase();
+ }
+ if (url.scheme == 'http' || url.scheme == 'https') {
+ if (!url.host) {
+ return false;
+ }
+ /* hostname labels may contain only alphanumeric characters, dots and hypens. */
+ if (!(new RegExp("^([a-zA-Z0-9][a-zA-Z0-9\\-\\.]*)$", "i")).test(url.host) || url.host.charAt(-1) == '.') {
+ return false;
+ }
+ }
+ /* some schemas allow the host to be empty */
+ if (!url.scheme || !url.host && url.scheme != 'mailto' && url.scheme != 'news' && url.scheme != 'file') {
+ return false;
+ }
+ return true;
+ })(url);
+
+ // all normal URLs including mailto:
+ if (validated) {
+ return url;
+ }
+
+ // '//example.com' (Shortcut for protocol.)
+ // '?query=test', #target
+ else if ((new RegExp("^(\\#|\\?|//)", "i")).test(url)) {
return url;
}
@@ -535,7 +562,7 @@ elgg.push_to_object_array = function(object, parent, value) {
object[parent] = []
}
- if (object[parent].indexOf(value) < 0) {
+ if ($.inArray(value, object[parent]) < 0) {
return object[parent].push(value);
}
@@ -553,7 +580,7 @@ elgg.is_in_object_array = function(object, parent, value) {
elgg.assertTypeOf('object', object);
elgg.assertTypeOf('string', parent);
- return typeof(object[parent]) != 'undefined' && object[parent].indexOf(value) >= 0;
+ return typeof(object[parent]) != 'undefined' && $.inArray(value, object[parent]) >= 0;
};
/**
@@ -569,4 +596,4 @@ elgg.initWhenReady = function() {
elgg.trigger_hook('init', 'system');
elgg.trigger_hook('ready', 'system');
}
-}; \ No newline at end of file
+};
diff --git a/js/lib/hooks.js b/js/lib/hooks.js
index 7bac471f6..5e1808e22 100644
--- a/js/lib/hooks.js
+++ b/js/lib/hooks.js
@@ -115,7 +115,7 @@ elgg.trigger_hook = function(name, type, params, value) {
return true;
});
- return (tempReturnValue !== null) ? tempReturnValue : returnValue;
+ return (tempReturnValue != null) ? tempReturnValue : returnValue;
};
/**
diff --git a/js/tests/ElggLanguagesTest.js b/js/tests/ElggLanguagesTest.js
index 1f66fc35b..9186ff5bb 100644
--- a/js/tests/ElggLanguagesTest.js
+++ b/js/tests/ElggLanguagesTest.js
@@ -6,7 +6,7 @@ ElggLanguagesTest.prototype.setUp = function() {
//Immediately execute some dummy "returned" javascript instead of sending
//an actual ajax request
$.ajax = function(settings) {
- var lang = settings.data.js.split('/')[1];
+ var lang = settings.data.language;
elgg.config.translations[lang] = {'language':lang};
};
};
diff --git a/js/tests/ElggLibTest.js b/js/tests/ElggLibTest.js
index dd0267c5c..c53c6331d 100644
--- a/js/tests/ElggLibTest.js
+++ b/js/tests/ElggLibTest.js
@@ -72,13 +72,36 @@ ElggLibTest.prototype.testNormalizeUrl = function() {
elgg.config.wwwroot = "http://elgg.org/";
[
- ['', elgg.config.wwwroot],
- ['test', elgg.config.wwwroot + 'test'],
- ['http://google.com', 'http://google.com'],
- ['//example.com', '//example.com'],
- ['/page', elgg.config.wwwroot + 'page'],
- ['mod/plugin/index.php', elgg.config.wwwroot + 'mod/plugin/index.php'],
+ ['', elgg.config.wwwroot],
+ ['test', elgg.config.wwwroot + 'test'],
+ ['http://example.com', 'http://example.com'],
+ ['https://example.com', 'https://example.com'],
+ ['http://example-time.com', 'http://example-time.com'],
+ ['//example.com', '//example.com'],
+
+ ['ftp://example.com/file', 'ftp://example.com/file'],
+ ['mailto:brett@elgg.org', 'mailto:brett@elgg.org'],
+ ['javascript:alert("test")', 'javascript:alert("test")'],
+ ['app://endpoint', 'app://endpoint'],
+
+ ['example.com', 'http://example.com'],
+ ['example.com/subpage', 'http://example.com/subpage'],
+
+ ['page/handler', elgg.config.wwwroot + 'page/handler'],
+ ['page/handler?p=v&p2=v2', elgg.config.wwwroot + 'page/handler?p=v&p2=v2'],
+ ['mod/plugin/file.php', elgg.config.wwwroot + 'mod/plugin/file.php'],
+ ['mod/plugin/file.php?p=v&p2=v2', elgg.config.wwwroot + 'mod/plugin/file.php?p=v&p2=v2'],
+ ['rootfile.php', elgg.config.wwwroot + 'rootfile.php'],
+ ['rootfile.php?p=v&p2=v2', elgg.config.wwwroot + 'rootfile.php?p=v&p2=v2'],
+
+ ['/page/handler', elgg.config.wwwroot + 'page/handler'],
+ ['/page/handler?p=v&p2=v2', elgg.config.wwwroot + 'page/handler?p=v&p2=v2'],
+ ['/mod/plugin/file.php', elgg.config.wwwroot + 'mod/plugin/file.php'],
+ ['/mod/plugin/file.php?p=v&p2=v2', elgg.config.wwwroot + 'mod/plugin/file.php?p=v&p2=v2'],
+ ['/rootfile.php', elgg.config.wwwroot + 'rootfile.php'],
+ ['/rootfile.php?p=v&p2=v2', elgg.config.wwwroot + 'rootfile.php?p=v&p2=v2'],
+
].forEach(function(args) {
assertEquals(args[1], elgg.normalize_url(args[0]));
});
-}; \ No newline at end of file
+};
diff --git a/js/tests/ElggPriorityListTest.js b/js/tests/ElggPriorityListTest.js
index 2549e0ee0..2329a8490 100644
--- a/js/tests/ElggPriorityListTest.js
+++ b/js/tests/ElggPriorityListTest.js
@@ -15,7 +15,7 @@ ElggPriorityListTest.prototype.testInsert = function() {
this.list.insert('bar', 501);
- assertEquals('foo', this.list.priorities_[501][0]);
+ assertEquals('bar', this.list.priorities_[501][0]);
};
ElggPriorityListTest.prototype.testInsertRespectsPriority = function() {
@@ -25,9 +25,9 @@ ElggPriorityListTest.prototype.testInsertRespectsPriority = function() {
this.list.insert(values[i], values[i]);
}
- this.list.forEach(function(elem, idx)) {
+ this.list.forEach(function(elem, idx) {
assertEquals(elem, idx);
- }
+ })
};
ElggPriorityListTest.prototype.testInsertHandlesDuplicatePriorities = function() {
diff --git a/js/tests/ElggSecurityTest.js b/js/tests/ElggSecurityTest.js
index f1111168f..c7309d55f 100644
--- a/js/tests/ElggSecurityTest.js
+++ b/js/tests/ElggSecurityTest.js
@@ -31,10 +31,10 @@ ElggSecurityTest.prototype.testAddTokenAcceptsString = function() {
str = "__elgg_ts=" + this.ts + "&__elgg_token=" + this.token;
input = "";
- assertEquals(str, elgg.security.addToken(input));
+ assertEquals('?' + str, elgg.security.addToken(input));
- input = "data=sofar";
- assertEquals(input+'&'+str, elgg.security.addToken(input));
+ input = "?data=sofar";
+ assertEquals(input + '&' + str, elgg.security.addToken(input));
};
diff --git a/js/tests/README b/js/tests/README
new file mode 100644
index 000000000..4f86b27c6
--- /dev/null
+++ b/js/tests/README
@@ -0,0 +1,24 @@
+Elgg JavaScript Unit Tests
+--------------------------
+
+Introduction
+============
+Elgg uses js-test-driver to run its unit tests. Instructions on obtaining,
+configuring, and using it are at http://code.google.com/p/js-test-driver/. It
+supports running the test in multiple browsers and debugging using web browser
+based debuggers. Visit its wiki at the Google Code site for more information.
+
+
+Sample Usage
+============
+ 1. Put jar file in the base directory of Elgg
+ 2. Run the server: java -jar JsTestDriver-1.3.3d.jar --port 4224
+ 3. Point a web browser at http://localhost:4224
+ 4. Run the tests: java -jar JsTestDriver-1.3.3d.jar --config js/tests/jsTestDriver.conf --basePath . --tests all
+
+
+Configuration Hints
+===================
+ * The port when running the server must be the same as listed in the
+ configuration file. If that port is being used, change the configuration file.
+ * The basePath must be the base directory of Elgg. \ No newline at end of file
diff --git a/js/tests/jsTestDriver.conf b/js/tests/jsTestDriver.conf
index 1bb06e811..cc0b5d373 100644
--- a/js/tests/jsTestDriver.conf
+++ b/js/tests/jsTestDriver.conf
@@ -1,9 +1,10 @@
-server: http://localhost:42442
+server: http://localhost:4224
load:
- - vendors/jquery/jquery-1.4.2.min.js
+ - vendors/jquery/jquery-1.6.4.min.js
- vendors/sprintf.js
- js/lib/elgglib.js
+ - js/lib/hooks.js
- js/classes/*.js
- js/lib/*.js
- js/tests/*.js \ No newline at end of file