diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/field.js | 11 | ||||
-rw-r--r-- | js/global.js | 23 |
2 files changed, 25 insertions, 9 deletions
diff --git a/js/field.js b/js/field.js index 778451daf..fdacd4728 100644 --- a/js/field.js +++ b/js/field.js @@ -738,10 +738,7 @@ $(function() { formatResult: function(suggestion, currentValue) { return (suggestion.data.name === '' ? suggestion.data.login : suggestion.data.name + ' (' + suggestion.data.login + ')') - .replace(/&/g, '&') - .replace(/</g, '<') - .replace(/>/g, '>') - .replace(/"/g, '"'); + .htmlEncode(); }, onSearchStart: function(params) { var that = $(this); @@ -800,11 +797,7 @@ $(function() { autoSelectFirst: true, formatResult: function(suggestion, currentValue) { // disable <b> wrapping of matched substring - return suggestion.value - .replace(/&/g, '&') - .replace(/</g, '<') - .replace(/>/g, '>') - .replace(/"/g, '"'); + return suggestion.value.htmlEncode(); }, onSelect: function() { this.focus(); diff --git a/js/global.js b/js/global.js index 7675fd98a..7ecd3d901 100644 --- a/js/global.js +++ b/js/global.js @@ -87,3 +87,26 @@ function display_value(field, value) { if (translated) return translated; return value; } + +// polyfill .trim +if (!String.prototype.trim) { + (function() { + // Make sure we trim BOM and NBSP + var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g; + String.prototype.trim = function() { + return this.replace(rtrim, ''); + }; + })(); +} + +// html encoding +if (!String.prototype.htmlEncode) { + (function() { + String.prototype.htmlEncode = function() { + return this.replace(/&/g, '&') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/"/g, '"'); + }; + })(); +} |