Skip to content

Commit

Permalink
fix for angular#5088
Browse files Browse the repository at this point in the history
  • Loading branch information
jtangelder committed Jan 15, 2014
1 parent 1413328 commit b705acf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/ngSanitize/filter/linky.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
<doc:scenario>
it('should linkify the snippet with urls', function() {
expect(using('#linky-filter').binding('snippet | linky')).
toBe('Pretty text with some links:&#10;' +
'<a href="http://angularjs.org/">http://angularjs.org/</a>,&#10;' +
'<a href="mailto:us@somewhere.org">us@somewhere.org</a>,&#10;' +
'<a href="mailto:another@somewhere.org">another@somewhere.org</a>,&#10;' +
toBe('Pretty text with some links:\n' +
'<a href="http://angularjs.org/">http://angularjs.org/</a>,\n' +
'<a href="mailto:us@somewhere.org">us@somewhere.org</a>,\n' +
'<a href="mailto:another@somewhere.org">another@somewhere.org</a>,\n' +
'and one more: <a href="ftp://127.0.0.1/">ftp://127.0.0.1/</a>.');
});
Expand Down
20 changes: 11 additions & 9 deletions src/ngSanitize/sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,16 @@ function decodeEntities(value) {
* @param value
* @returns escaped text
*/
function encodeEntities(value) {
return value.
replace(/&/g, '&amp;').
replace(NON_ALPHANUMERIC_REGEXP, function(value){
function encodeEntities(value, replace_non_alphanumeric) {
value = value.replace(/&/g, '&amp;');

if(replace_non_alphanumeric) {
value = value.replace(NON_ALPHANUMERIC_REGEXP, function(value){
return '&#' + value.charCodeAt(0) + ';';
}).
replace(/</g, '&lt;').
replace(/>/g, '&gt;');
});
}

return value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

/**
Expand Down Expand Up @@ -435,7 +437,7 @@ function htmlSanitizeWriter(buf, uriValidator){
out(' ');
out(key);
out('="');
out(encodeEntities(value));
out(encodeEntities(value, true));
out('"');
}
});
Expand All @@ -455,7 +457,7 @@ function htmlSanitizeWriter(buf, uriValidator){
},
chars: function(chars){
if (!ignore) {
out(encodeEntities(chars));
out(encodeEntities(chars, false));
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions test/ngSanitize/sanitizeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('HTML', function() {

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

Expand Down Expand Up @@ -191,7 +191,7 @@ describe('HTML', function() {
});

it('should allow multiline strings', function() {
expectHTML('\na\n').toEqual('&#10;a\&#10;');
expectHTML('\na\n').toEqual('\na\n');
});

describe('htmlSanitizerWriter', function() {
Expand Down

0 comments on commit b705acf

Please sign in to comment.