-
Notifications
You must be signed in to change notification settings - Fork 35
issue #88: Prevent infinite looping on empty/short HTML comment #89
Changes from 4 commits
f8a4c92
2ecd932
759446f
4ddfd2f
1653fab
0ce8431
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -511,6 +511,28 @@ public function testMultiQuoteInput() | |||||||||||||||||||||||||
$this->assertEquals($expected, $filter->filter($input)); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
public function badCommentProvider() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
return [ | ||||||||||||||||||||||||||
['A <!--> B', 'A '], // Should be treated as just an open | ||||||||||||||||||||||||||
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. I love the tests. But just curious, would tests about these scenarios make sense as well:
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. @TotalWipeOut would you be able to add scenarios mentioned above? I would suggest also: 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. case with nested comment is invalid (it is not possible to have nested comments).
and as the result I've got:
so not 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. Yes, I will add these extra tests 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. @webimpress and @icanhazstring We have an issue with this test: 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. @TotalWipeOut I've checked it, and it looks like desired behaviour. We have tests to cover these scenarios, that zend-filter/test/StripTagsTest.php Lines 200 to 211 in 922fe11
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. @webimpress totally fine with me to match the filter with modern browser behavior. 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. @webimpress I agree, it was designed to strip orphan How do I proceed? 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. @TotalWipeOut I would keep it for now, as changing it now will be BC Break. We should log another issue and change the behaviour in next major version. So for now - in your test - expected value should be 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. OK, thanks. I have added the requested tests, 11 in total now 🙂 |
||||||||||||||||||||||||||
['A <!---> B', 'A '], // Should be treated as just an open | ||||||||||||||||||||||||||
['A <!----> B', 'A B'], | ||||||||||||||||||||||||||
['A <!-- --> B', 'A B'], | ||||||||||||||||||||||||||
['A <!--My favorite operators are > and <!--> B', 'A B'], | ||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||
* @dataProvider badCommentProvider | ||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||
* @param string $input | ||||||||||||||||||||||||||
* @param string $expected | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
public function testBadCommentTags($input, $expected) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
$this->assertEquals($expected, $this->_filter->filter($input)); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||
* @group ZF-10256 | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
|
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.
Not sure why, but before we expect closing tag to match reg exp
--\s*>
.Now, we explicitly expecting no any spaces between
--
and>
.Do you think expecting some spaces there was a bug? I can't see any other test which fail because of that change, and also I haven't seen anything about these spaces in the specs.
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 couldn't see why it was doing that either. Running some additional tests this loops now handles comments in the same way
strip_tags
does. So i can only think this was a hidden feature/bug?With the string
test<!---- -- > -- > -->
the previous version returnedtest -- --
where as now it returnstest
Should the previous behaviour be restored?
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.
Honestly, I think the current behaviour is correct and comply with the html comment spec. Also, as you said, the same way
strip_tags
behaves, so I think it's right. You can add this test case as well.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.
OK, cool. Test added