Refactored and cleaned up Sanitizer + bug fix.

* Moved all constants to a singleton constants object
* Moved couple methods to mediawiki.Util.js
* Fixed url regexp bug -- relative urls weren't being matched
  but, this bug escaped through because the previous url regexp
  had a typo (which means url sanitization wasn't being done by
  the previous code).  This also means we have to either find
  sanitizer tests or add new ones so these bugs are caught.  Maybe
  parserTests.txt is not the right place for this?

Change-Id: Ia05e1d1596bb9bc4a9eb21d7c77248f5626a710e
This commit is contained in:
Subramanya Sastry 2012-07-28 11:44:09 -05:00
parent 604a15df21
commit e2197d4d89
2 changed files with 615 additions and 642 deletions

File diff suppressed because it is too large Load diff

View file

@ -64,8 +64,8 @@ var Util = {
* @returns {Boolean}: True if token is block-level, false otherwise.
*/
isBlockToken: function ( token ) {
if ( token.constructor === TagTk ||
token.constructor === EndTagTk ||
if ( token.constructor === TagTk ||
token.constructor === EndTagTk ||
token.constructor === SelfclosingTagTk ) {
return Util.isBlockTag( token.name.toLowerCase() );
} else {
@ -290,9 +290,32 @@ var Util = {
} else {
return text;
}
},
arrayToHash: function(a) {
var h = {};
for (var i = 0, n = a.length; i < n; i++) {
h[a[i]] = 1;
}
return h;
},
// Returns the utf8 encoding of the code point
codepointToUtf8: function(cp) {
return unescape(encodeURIComponent(cp));
},
// Returns true if a given Unicode codepoint is a valid character in XML.
validateCodepoint: function(cp) {
return (cp === 0x09) ||
(cp === 0x0a) ||
(cp === 0x0d) ||
(cp >= 0x20 && cp <= 0xd7ff) ||
(cp >= 0xe000 && cp <= 0xfffd) ||
(cp >= 0x10000 && cp <= 0x10ffff);
}
};
if (typeof module == "object") {
if (typeof module === "object") {
module.exports.Util = Util;
}