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

Commit

Permalink
fix(ngSanitize): ensure html is a string in htmlParser()
Browse files Browse the repository at this point in the history
Previously, $sanitize(nonString) would throw. Now, the type is converted to a string before any work
is done.

Closes #8417
Closes #8416
  • Loading branch information
caitp committed Jul 30, 2014
1 parent afe93ea commit 9ee0755
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ngSanitize/sanitize.js
Expand Up @@ -232,6 +232,13 @@ function makeMap(str) {
* @param {object} handler
*/
function htmlParser( html, handler ) {
if (typeof html !== 'string') {
if (html === null || typeof html === 'undefined') {
html = '';
} else {
html = '' + html;
}
}
var index, chars, match, stack = [], last = html, text;
stack.last = function() { return stack[ stack.length - 1 ]; };

Expand Down
10 changes: 10 additions & 0 deletions test/ngSanitize/sanitizeSpec.js
Expand Up @@ -228,6 +228,16 @@ describe('HTML', function() {
.toEqual('<p> 10 &lt; <span>100</span> </p>');
});

it('should accept non-string arguments', function() {
expectHTML(null).toBe('');
expectHTML(undefined).toBe('');
expectHTML(42).toBe('42');
expectHTML({}).toBe('[object Object]');
expectHTML([1, 2, 3]).toBe('1,2,3');
expectHTML(true).toBe('true');
expectHTML(false).toBe('false');
});

describe('htmlSanitizerWriter', function() {
/* global htmlSanitizeWriter: false */
if (angular.isUndefined(window.htmlSanitizeWriter)) return;
Expand Down

0 comments on commit 9ee0755

Please sign in to comment.