diff --git a/src/ngSanitize/sanitize.js b/src/ngSanitize/sanitize.js index fae50aac259d..593e62f59ef1 100644 --- a/src/ngSanitize/sanitize.js +++ b/src/ngSanitize/sanitize.js @@ -277,6 +277,10 @@ function htmlParser( html, handler ) { html = html.substring( match[0].length ); match[0].replace( START_TAG_REGEXP, parseStartTag ); chars = false; + } else { + // no ending tag found + if (handler.chars) handler.chars( '<' ); + html = html.substring(1); } } diff --git a/test/ngSanitize/sanitizeSpec.js b/test/ngSanitize/sanitizeSpec.js index 76a48087576e..611d9664cc73 100644 --- a/test/ngSanitize/sanitizeSpec.js +++ b/test/ngSanitize/sanitizeSpec.js @@ -21,6 +21,7 @@ describe('HTML', function() { var handler, start, text, comment; beforeEach(function() { + text = ""; handler = { start: function(tag, attrs, unary){ start = { @@ -35,7 +36,7 @@ describe('HTML', function() { }); }, chars: function(text_){ - text = text_; + text += text_; }, end:function(tag) { expect(tag).toEqual(start.tag); @@ -81,6 +82,16 @@ describe('HTML', function() { expect(text).toEqual('text'); }); + it('should parse unterminated tags as regular content', function() { + htmlParser(' 10 < 100
', handler); + expect(text).toEqual(' 10 < 100 '); + }); + it('should parse newlines in tags', function() { htmlParser('<\ntag\n attr="value"\n>text<\n/\ntag\n>', handler); expect(start).toEqual({tag:'tag', attrs:{attr:'value'}, unary:false}); @@ -195,6 +206,12 @@ describe('HTML', function() { expectHTML('\na\n').toEqual(' a '); }); + it('should accept tag delimiters such as "<" inside real tags (with nesting)', function() { + //this is an integrated version of the 'should accept tag delimiters such as "<" inside real tags' test + expectHTML('10 < 100
') + .toEqual('10 < 100
'); + }); + describe('htmlSanitizerWriter', function() { /* global htmlSanitizeWriter: false */ if (angular.isUndefined(window.htmlSanitizeWriter)) return;