Skip to content

Commit b705acf

Browse files
committed
fix for angular#5088
1 parent 1413328 commit b705acf

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/ngSanitize/filter/linky.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@
7070
<doc:scenario>
7171
it('should linkify the snippet with urls', function() {
7272
expect(using('#linky-filter').binding('snippet | linky')).
73-
toBe('Pretty text with some links:&#10;' +
74-
'<a href="http://angularjs.org/">http://angularjs.org/</a>,&#10;' +
75-
'<a href="mailto:us@somewhere.org">[email protected]</a>,&#10;' +
76-
'<a href="mailto:[email protected]">[email protected]</a>,&#10;' +
73+
toBe('Pretty text with some links:\n' +
74+
'<a href="http://angularjs.org/">http://angularjs.org/</a>,\n' +
75+
'<a href="mailto:us@somewhere.org">[email protected]</a>,\n' +
76+
'<a href="mailto:[email protected]">[email protected]</a>,\n' +
7777
'and one more: <a href="ftp://127.0.0.1/">ftp://127.0.0.1/</a>.');
7878
});
7979

src/ngSanitize/sanitize.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,16 @@ function decodeEntities(value) {
395395
* @param value
396396
* @returns escaped text
397397
*/
398-
function encodeEntities(value) {
399-
return value.
400-
replace(/&/g, '&amp;').
401-
replace(NON_ALPHANUMERIC_REGEXP, function(value){
398+
function encodeEntities(value, replace_non_alphanumeric) {
399+
value = value.replace(/&/g, '&amp;');
400+
401+
if(replace_non_alphanumeric) {
402+
value = value.replace(NON_ALPHANUMERIC_REGEXP, function(value){
402403
return '&#' + value.charCodeAt(0) + ';';
403-
}).
404-
replace(/</g, '&lt;').
405-
replace(/>/g, '&gt;');
404+
});
405+
}
406+
407+
return value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
406408
}
407409

408410
/**
@@ -435,7 +437,7 @@ function htmlSanitizeWriter(buf, uriValidator){
435437
out(' ');
436438
out(key);
437439
out('="');
438-
out(encodeEntities(value));
440+
out(encodeEntities(value, true));
439441
out('"');
440442
}
441443
});
@@ -455,7 +457,7 @@ function htmlSanitizeWriter(buf, uriValidator){
455457
},
456458
chars: function(chars){
457459
if (!ignore) {
458-
out(encodeEntities(chars));
460+
out(encodeEntities(chars, false));
459461
}
460462
}
461463
};

test/ngSanitize/sanitizeSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe('HTML', function() {
160160

161161
it('should handle entities', function() {
162162
var everything = '<div rel="!@#$%^&amp;*()_+-={}[]:&#34;;\'&lt;&gt;?,./`~ &#295;">' +
163-
'!@#$%^&amp;*()_+-={}[]:&#34;;\'&lt;&gt;?,./`~ &#295;</div>';
163+
'!@#$%^&amp;*()_+-={}[]:";\'&lt;&gt;?,./`~ ħ</div>';
164164
expectHTML(everything).toEqual(everything);
165165
});
166166

@@ -191,7 +191,7 @@ describe('HTML', function() {
191191
});
192192

193193
it('should allow multiline strings', function() {
194-
expectHTML('\na\n').toEqual('&#10;a\&#10;');
194+
expectHTML('\na\n').toEqual('\na\n');
195195
});
196196

197197
describe('htmlSanitizerWriter', function() {

0 commit comments

Comments
 (0)