This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix: text that looks like an html tag but is not causes [$sanitize:badparse] error #8193
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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('<a text1 text2 <a text1 text2', handler); | ||
expect(text).toEqual('<a text1 text2 <a text1 text2'); | ||
}); | ||
|
||
it('should accept tag delimiters such as "<" inside real tags', function() { | ||
htmlParser('<p> 10 < 100 </p>', handler); | ||
expect(text).toEqual(' 10 < 100 '); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we convert the |
||
}); | ||
|
||
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('<p> 10 < <span>100</span> </p>') | ||
.toEqual('<p> 10 < <span>100</span> </p>'); | ||
}); | ||
|
||
describe('htmlSanitizerWriter', function() { | ||
/* global htmlSanitizeWriter: false */ | ||
if (angular.isUndefined(window.htmlSanitizeWriter)) return; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong because it breaks html parsing rules. browsers either ignore this and throw it away or try to autocorrect the html.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this is correct --- I guess we need a non-alpha character to precede the < (in testing, <ê, <3, <- are all fine). I don't think we can come even close to being as crazy as the actual parsing rules though, that would be way too much code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should sanitize convert the
<
to<
in text that looks like unterminated tags?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes (for example, http://jsfiddle.net/fMDyg/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you take it from here and do the necessary change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can have a go at it :>