Fix stack overflow with CData edge case#9
Open
edwardsnjd wants to merge 1 commit into
Open
Conversation
When a CData block content ends with one or more "]" the parser fails with a stack overflow. This commit adds some tests for edge cases and changes the implementation to pass.
edwardsnjd
commented
Aug 28, 2019
| , test "cdata 8" <| expectSucceed "<a>a<![CDATA[b]]>c</a>" (Element "a" [] [ Text "abc" ]) | ||
| , test "cdata 9" <| expectSucceed "<a><![CDATA[a[b]c]]></a>" (Element "a" [] [ Text "a[b]c" ]) | ||
| , test "cdata 10" <| expectSucceed "<a><![CDATA[[b]c]]></a>" (Element "a" [] [ Text "[b]c" ]) | ||
| , test "cdata 11" <| expectSucceed "<a><![CDATA[a[b]]]></a>" (Element "a" [] [ Text "a[b]" ]) |
Author
There was a problem hiding this comment.
This is a case that was previously failing due to the trailing ].
edwardsnjd
commented
Aug 28, 2019
| , test "cdata 10" <| expectSucceed "<a><![CDATA[[b]c]]></a>" (Element "a" [] [ Text "[b]c" ]) | ||
| , test "cdata 11" <| expectSucceed "<a><![CDATA[a[b]]]></a>" (Element "a" [] [ Text "a[b]" ]) | ||
| , test "cdata 12" <| expectSucceed "<a><![CDATA[a[[b]]c]]></a>" (Element "a" [] [ Text "a[[b]]c" ]) | ||
| , test "cdata 13" <| expectSucceed "<a><![CDATA[ab<![CDATA[cd]]></a>" (Element "a" [] [ Text "ab<![CDATA[cd" ]) |
Author
There was a problem hiding this comment.
Tests 13 and 14 are overkill but I wanted to prove that nested CData blocks are handled correctly.
edwardsnjd
commented
Aug 28, 2019
| , test "cdata fail 3" <| expectFail "<a><![CDATA[]]</a>" | ||
| , test "cdata fail 4" <| expectFail "<a><![CDATA[abc</a>" | ||
| , test "cdata fail 5" <| expectFail "<a>abc<![CDATA[</a>" | ||
| , test "cdata fail 6" <| expectFail "<a>abc<![CDATA[def</a>" |
Author
There was a problem hiding this comment.
Again, these are probably overkill but prove that invalid CData blocks do fail.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Thanks for this great library!
I hit an issue when parsing CData content ending with a square bracket,
]:I added some tests for this case and had a go at making them all pass again. My understanding of the spec is that nothing is parsed inside the CData content so we can safely chomp until the end token: https://www.w3.org/TR/REC-xml/#sec-cdata-sect
I'm an elm newcomer and didn't fully understand the existing implementation, so would appreciate any input.