-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added modules/Escaping with the first useful methods.
query/VirtualElement now using the escaping.
- Loading branch information
Showing
2 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
define([], | ||
function () { | ||
var htmlEntityMap = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
'\'': ''', | ||
'/': '&x2F;' | ||
}; | ||
|
||
var htmlEscapeRegEx = (function () { | ||
var entities = []; | ||
for (var entity in htmlEntityMap) { | ||
entities.push(entity); | ||
} | ||
return new RegExp('(' + entities.join('|') + ')', 'g'); | ||
})(); | ||
|
||
var Escape = { | ||
// moved from modules/escapeRegEx | ||
forRegEx: function escapeRegEx(string) { | ||
return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); | ||
}, | ||
forHTML: function (value) { | ||
if (!blocks.isString(value)) { | ||
return value; | ||
} | ||
return value.replace(htmlEscapeRegEx, function (entity) { | ||
return htmlEntityMap[entity]; | ||
}); | ||
}, | ||
// This is only valid because jsblocks forces (inserts itself) double quotes for attributes | ||
// don't use this in other cases | ||
forHTMLAttributes: function (value) { | ||
if (blocks.isString(value)) { | ||
return value.replace(/"/g, '"'); | ||
} | ||
return value; | ||
} | ||
}; | ||
return Escape; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters