-
-
Notifications
You must be signed in to change notification settings - Fork 753
Fix XML parser in std.xml throws TagException if the attr value is put in apostrophes #4064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1059,9 +1059,10 @@ class Tag | |
| munch(s,whitespace); | ||
| reqc(s,'='); | ||
| munch(s,whitespace); | ||
| reqc(s,'"'); | ||
| string val = decode(munch(s,"^\""), DecodeMode.LOOSE); | ||
| reqc(s,'"'); | ||
| char quote = requireOneOf(s,"'\""); | ||
| char[2] notQuote = ['^', quote]; | ||
| string val = decode(munch(s,notQuote[]), DecodeMode.LOOSE); | ||
| reqc(s,quote); | ||
| munch(s,whitespace); | ||
| attr[key] = val; | ||
| } | ||
|
|
@@ -2712,6 +2713,16 @@ EOS"; | |
| } | ||
| } | ||
|
|
||
| unittest | ||
| { | ||
| string test_xml = `<?xml version="1.0" encoding='UTF-8'?><stream:stream | ||
| xmlns:stream="http://etherx.'jabber'.org/streams" | ||
| xmlns="jabber:'client'" from='jid.pl' id="587a5767" | ||
| xml:lang="en" version="1.0"></stream:stream>`; | ||
|
|
||
| DocumentParser parser = new DocumentParser(test_xml); | ||
| } | ||
|
|
||
| unittest | ||
| { | ||
| string s = q"EOS | ||
|
|
@@ -2858,6 +2869,15 @@ private | |
| s = s[1..$]; | ||
| } | ||
|
|
||
| char requireOneOf(ref string s, string chars) | ||
| { | ||
| if (s.length == 0 || indexOf(chars,s[0]) == -1) | ||
| throw new TagException(""); | ||
| char ch = s[0]; | ||
| s = s[1..$]; | ||
| return ch; | ||
| } | ||
|
|
||
| size_t hash(string s,size_t h=0) @trusted nothrow | ||
| { | ||
| return typeid(s).getHash(&s) + h; | ||
|
|
@@ -2970,3 +2990,5 @@ private | |
| throw new XMLException(s); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
Contributor
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. Now there are three newlines at the end. One would be enough :) |
||
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.
Should this also test that the parsed structure matches the expected structure? I.e., that the value of
encodingis correctly parsed asUTF-8?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.
(And the
xmlnsin thestream:streamtag contains the entire value?)Also, what about a tag like
<p attr='a"b"c'/>? Does the parser handle that correctly?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 @quickfur it handles cases with " inside properly.I tested it.
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.
Yeah, that should be tested. Unfortunately, std.xml doesn't seem to generate events for the root element, making this a bit more cumbersome than it should be.
@CoderAbhishek, if your motivation is still up for it, please add
asserts for the values of the attributes. You can see how to do that in theunittestblock that's below the one you added. Like there, you'll have to wrap things in a new root element. Also include a case likeattr='a"b"c'.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, once the asserts are added, we can merge this. Thanks!