-
-
Notifications
You must be signed in to change notification settings - Fork 745
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
Conversation
string atr_val_put_chars="'\""; //chars in which tags can be put into | ||
reqs(s,atr_val_put_chars); | ||
string val = decode(munch(s,"^'\""), DecodeMode.LOOSE); | ||
reqs(s,atr_val_put_chars); |
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 behaves incorrectly for stuff like foo="bar 'baz' qux"
. You have to check which quote is used in the beginning, and stop when hitting it again.
When you make a pull request for a bugzilla issue, please leave a comment on the issue page with the pull request URL, and add the 'pull' keyword. You can also assign the issue to yourself. Please add tests (in |
I see you've added a commit. GitHub does not send out notifications for new commits, so generally you need to leave a comment if you want reviewers to notice that you did work on a pull request. Also, you should add "fix issue 4509" to the commit message. This way the issue gets closed automatically when your pull request is accepted. And in the end, you should probably squash the commits into one. But we can polish up the code first, before dealing with these formalities. |
@@ -1,6 +1,6 @@ | |||
// Written in the D programming language. | |||
|
|||
/** | |||
/* |
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 a mistake, isn't it?
|
@aG0aep6G I have implemented your suggestions. |
string val = decode(munch(s,"^\""), DecodeMode.LOOSE); | ||
reqc(s,'"'); | ||
char quote = requireOneOf(s,"'\""); | ||
char[] notQuote = ['^', quote]; |
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.
You could still make this a char[2]
to avoid an allocation. I don't know how important that is here, though. You would have to make it notQuote[]
below then.
I was going to suggest you add asserts for the attribute values, but apparently no events are generated for the root element ... sigh ... That's a battle for another day, I suppose. |
@@ -2970,3 +2990,5 @@ private | |||
throw new XMLException(s); | |||
} | |||
} | |||
|
|||
|
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.
Now there are three newlines at the end. One would be enough :)
For some reason I did not get an email notification for that comment. I guess it's because the comment is on a commit rather than the pull request itself. Code looks good to me now, aside from too many newlines at the end ;) I think we should squash the commits into one, and format the commit message a bit nicer. If you're not super familiar with git, here's how I'd do that (not necessarily the quickest/best way to do it):
|
xmlns="jabber:'client'" from='jid.pl' id="587a5767" | ||
xml:lang="en" version="1.0"></stream:stream>`; | ||
|
||
DocumentParser parser = new DocumentParser(test_xml); |
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 encoding
is correctly parsed as UTF-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 xmlns
in the stream:stream
tag 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.
Should this also test that the parsed structure matches the expected structure? I.e., that the value of encoding is correctly parsed as UTF-8?
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 assert
s for the values of the attributes. You can see how to do that in the unittest
block that's below the one you added. Like there, you'll have to wrap things in a new root element. Also include a case like attr='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!
Fixes issue 4509 - XML parser in std.xml throws TagException if the attr value is put in apostrophes.
@aG0aep6G I've squashed the commits and updated PR. |
@CoderAbhishek Please add the asserts suggested by the other reviewers. Once you do this one of us will merge the pull request. |
Sorry for delay,I'll do so soon. On Sat, Mar 19, 2016 at 4:14 AM, Brian Schott notifications@github.com
|
Ping @CoderAbhishek |
Sorry I am a bit busy these days and I won't be able to complete it, at least not in a few weeks. Hope I have not disappointed you. |
Resubmitted with asserts as #4567. |
#4567 has been merged. This can be closed now. |
OK, closing. |
This commit is an intended fix to https://issues.dlang.org/show_bug.cgi?id=4509
I'm a new contributer to Phobos,please tell me if there is something I should change.I have tested it on my local machine.