Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngSanitize): prevent decodeEntities from prepending original text… #5193

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ngSanitize/sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ function decodeEntities(value) {
// Note: IE8 does not preserve spaces at the start/end of innerHTML
var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/;
var parts = spaceRe.exec(value);
parts[0] = '';
if (parts[2]) {
hiddenPre.innerHTML=parts[2].replace(/</g,"&lt;");
parts[2] = hiddenPre.innerText || hiddenPre.textContent;
}
parts[0] = '';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really explain why moving this assignment has that strong of an effect --- the VM is doing some weird things. But it does fix the problem

return parts.join('');
}

Expand Down
6 changes: 6 additions & 0 deletions test/ngSanitize/sanitizeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,10 @@ describe('HTML', function() {
expect(sanitizeText('a<div>&</div>c')).toEqual('a&lt;div&gt;&amp;&lt;/div&gt;c');
});
});

describe('decodeEntities', function() {
it('should not prepend the original string to the output', function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, and numerous other tests in ngSanitize were failing on OSX 10.9 + Safari 7, it would be really nice to get this configuration added to the CI servers, but SauceLabs don't support it :( (failing tests: https://gist.github.com/caitp/7699674) --- Each of these failures are passing after applying this patch.

expect(decodeEntities('John Due &#9786;')).toEqual('John Due ☺');
});
});
});