diff --git a/src/ngSanitize/filter/linky.js b/src/ngSanitize/filter/linky.js index 2c05d84e5c1f..d887cf9cbdf9 100644 --- a/src/ngSanitize/filter/linky.js +++ b/src/ngSanitize/filter/linky.js @@ -70,10 +70,10 @@ it('should linkify the snippet with urls', function() { expect(using('#linky-filter').binding('snippet | linky')). - toBe('Pretty text with some links: ' + - 'http://angularjs.org/, ' + - 'us@somewhere.org, ' + - 'another@somewhere.org, ' + + toBe('Pretty text with some links:\n' + + 'http://angularjs.org/,\n' + + 'us@somewhere.org,\n' + + 'another@somewhere.org,\n' + 'and one more: ftp://127.0.0.1/.'); }); diff --git a/src/ngSanitize/sanitize.js b/src/ngSanitize/sanitize.js index 5e45eb338b47..a700c819736d 100644 --- a/src/ngSanitize/sanitize.js +++ b/src/ngSanitize/sanitize.js @@ -395,14 +395,16 @@ function decodeEntities(value) { * @param value * @returns escaped text */ -function encodeEntities(value) { - return value. - replace(/&/g, '&'). - replace(NON_ALPHANUMERIC_REGEXP, function(value){ +function encodeEntities(value, replace_non_alphanumeric) { + value = value.replace(/&/g, '&'); + + if(replace_non_alphanumeric) { + value = value.replace(NON_ALPHANUMERIC_REGEXP, function(value){ return '&#' + value.charCodeAt(0) + ';'; - }). - replace(//g, '>'); + }); + } + + return value.replace(//g, '>'); } /** @@ -435,7 +437,7 @@ function htmlSanitizeWriter(buf, uriValidator){ out(' '); out(key); out('="'); - out(encodeEntities(value)); + out(encodeEntities(value, true)); out('"'); } }); @@ -455,7 +457,7 @@ function htmlSanitizeWriter(buf, uriValidator){ }, chars: function(chars){ if (!ignore) { - out(encodeEntities(chars)); + out(encodeEntities(chars, false)); } } }; diff --git a/test/ngSanitize/sanitizeSpec.js b/test/ngSanitize/sanitizeSpec.js index fbffbba5cbeb..3fef8fad2494 100644 --- a/test/ngSanitize/sanitizeSpec.js +++ b/test/ngSanitize/sanitizeSpec.js @@ -160,7 +160,7 @@ describe('HTML', function() { it('should handle entities', function() { var everything = '
' + - '!@#$%^&*()_+-={}[]:";\'<>?,./`~ ħ
'; + '!@#$%^&*()_+-={}[]:";\'<>?,./`~ ħ'; expectHTML(everything).toEqual(everything); }); @@ -191,7 +191,7 @@ describe('HTML', function() { }); it('should allow multiline strings', function() { - expectHTML('\na\n').toEqual(' a\ '); + expectHTML('\na\n').toEqual('\na\n'); }); describe('htmlSanitizerWriter', function() {