From 26ff3f62bcfb4552cf638f1604a2707624250894 Mon Sep 17 00:00:00 2001 From: Sylvain Hamel Date: Sat, 5 Jul 2014 01:03:52 -0400 Subject: [PATCH] fix: text that looks like an html tag but is not causes [$sanitize:badparse] error --- src/ngSanitize/sanitize.js | 4 ++++ test/ngSanitize/sanitizeSpec.js | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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;