aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorR. Merkert2013-08-17 19:09:28 -0400
committerVojta Jina2013-09-11 22:40:09 +0200
commit21e9e8cf68ef007136da6cc212d2f1f252fb668a (patch)
tree39bd8e8fb2c2b8fc267d714e4b85b7b6604c0e46
parentbf512bb8ee696f7644879cf0ba33e01cbf9e2153 (diff)
downloadangular.js-21e9e8cf68ef007136da6cc212d2f1f252fb668a.tar.bz2
fix(ngSanitize): sanitizer should not accept <!--> as a valid comment
According to http://validator.w3.org/ , <!--> is not a valid comment and neither is any comment containing the -- substring.
-rw-r--r--src/ngSanitize/sanitize.js5
-rw-r--r--test/ngSanitize/sanitizeSpec.js34
2 files changed, 36 insertions, 3 deletions
diff --git a/src/ngSanitize/sanitize.js b/src/ngSanitize/sanitize.js
index 3d904ad1..ffee51df 100644
--- a/src/ngSanitize/sanitize.js
+++ b/src/ngSanitize/sanitize.js
@@ -210,9 +210,10 @@ function htmlParser( html, handler ) {
// Comment
if ( html.indexOf("<!--") === 0 ) {
- index = html.indexOf("-->");
+ // comments containing -- are not allowed unless they terminate the comment
+ index = html.indexOf("--", 4);
- if ( index >= 0 ) {
+ if ( index >= 0 && html.lastIndexOf("-->", index) === index) {
if (handler.comment) handler.comment( html.substring( 4, index ) );
html = html.substring( index + 3 );
chars = false;
diff --git a/test/ngSanitize/sanitizeSpec.js b/test/ngSanitize/sanitizeSpec.js
index f97e86a6..ae1271f0 100644
--- a/test/ngSanitize/sanitizeSpec.js
+++ b/test/ngSanitize/sanitizeSpec.js
@@ -15,7 +15,7 @@ describe('HTML', function() {
describe('htmlParser', function() {
if (angular.isUndefined(window.htmlParser)) return;
- var handler, start, text;
+ var handler, start, text, comment;
beforeEach(function() {
handler = {
start: function(tag, attrs, unary){
@@ -35,10 +35,42 @@ describe('HTML', function() {
},
end:function(tag) {
expect(tag).toEqual(start.tag);
+ },
+ comment:function(comment_) {
+ comment = comment_;
}
};
});
+ it('should parse comments', function() {
+ htmlParser('<!--FOOBAR-->', handler);
+ expect(comment).toEqual('FOOBAR');
+ });
+
+ it('should throw an exception for invalid comments', function() {
+ var caught=false;
+ try {
+ htmlParser('<!-->', handler);
+ }
+ catch (ex) {
+ caught = true;
+ // expected an exception due to a bad parse
+ }
+ expect(caught).toBe(true);
+ });
+
+ it('double-dashes are not allowed in a comment', function() {
+ var caught=false;
+ try {
+ htmlParser('<!-- -- -->', handler);
+ }
+ catch (ex) {
+ caught = true;
+ // expected an exception due to a bad parse
+ }
+ expect(caught).toBe(true);
+ });
+
it('should parse basic format', function() {
htmlParser('<tag attr="value">text</tag>', handler);
expect(start).toEqual({tag:'tag', attrs:{attr:'value'}, unary:false});