Possible bug parsing URI without some components.

15 views
Skip to first unread message

NoAntzWk

unread,
Dec 14, 2010, 1:16:53 PM12/14/10
to uri-grammar
Hi,

I think that is a bug. Parsing a URI without a user info hasn't the
expected result. That is, the parser works fine but the component
userinfo is initialized with the host value. Example:

uri::components<string::const_iterator> c;
uri::grammar<string::const_iterator> g(c);
std::string uri = "http://172.26.0.26/?f=1
if(qi::parse(uri.begin(), uri.end(), g))
{
std::string userinfo (c.userinfo.begin(),
c.userinfo.end());
assert(userinfo.empty());

std::string port (c.port.begin(), c.port.end());
assert(port.empty());
}

The assert fails because userinfo is initialized with "172.26.0.26".
However the port works fine and it is initialized as empty string!
I would expect that UserInfo was initialized as empty string.

I have not find the bug and I don't know if its a grammar definition
error or an implementation issue. Can anyone confirm the issue?

Thanks in advance.

Best regards.

Braden McDaniel

unread,
Dec 15, 2010, 12:59:44 AM12/15/10
to uri-g...@googlegroups.com

Does sound like a bug. Can you go ahead and file it? I should have a
chance to investigate this (and the other issue you raised) in a few
days.

--
Braden McDaniel <bra...@endoframe.com>

Braden McDaniel

unread,
Dec 24, 2010, 11:52:18 PM12/24/10
to uri-g...@googlegroups.com
On Tue, 2010-12-14 at 10:16 -0800, NoAntzWk wrote:

I believe I've fixed this.

The problem is that Spirit doesn't know that it *isn't* parsing the
userinfo until it *doesn't* see the "@". But the userinfo iterators
were getting assigned *before* encountering "@" (because the range
shouldn't include the "@").

There are at least a couple of ways to solve this; the simplest (I
think) is just to introduce a temporary variable that can hold onto the
iterators while their assignment to the components<>::userinfo is
deferred until the "@" is seen. And that's what I've done.

I've also added tests to the testsuite to cover this case.

Thanks for finding this.

--
Braden McDaniel <bra...@endoframe.com>

NoAntzWk

unread,
Dec 30, 2010, 3:40:43 AM12/30/10
to uri-g...@googlegroups.com
Hi Braden!

Your fix works fine. Thank you for your answer!

Best regards.
Reply all
Reply to author
Forward
0 new messages