Error parsing URL when SwazooURI is passed a URL without protocol and hostname (e.g. /abc instead of http://xyz.com/abc)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Error parsing URL when SwazooURI is passed a URL without protocol and hostname (e.g. /abc instead of http://xyz.com/abc)

Yar Hwee Boon-3
Hi,

First timer running Swazoo (2.1 on Squeak).

Following SUnit test case illustrates the problem (encoding
http://abc.com doesn't fix it):

testUrlWithoutHostName
        | uri |
        uri := SwazooURI fromString:'/click?key1=v1&url=http://abc.com'.
        self assert: uri protocol = 'http'.
        self assert: uri hostname isNil.   "This is parsed as abc.com"
        self assert: uri port = 80.
        self assert: uri identifier = '/click'.
        self assert: (uri queryAt: 'key1') = 'v1'.
        self assert: (uri queryAt: 'url') = 'http://abc.com'.

Any suggestion how to fix it? The SwazooURITest suggest the protocol
and hostname will always be around.. Thanks.

--
Hwee-Boon

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Swazoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swazoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Error parsing URL when SwazooURI is passed a URL without protocol and hostname (e.g. /abc instead of http://xyz.com/abc)

Bruce Badger
Hwee-Boon,

Thanks for the test.  It highlighted a bug in the Hyper version of the
URI parsing too, though not the one you saw.  The test coded as
follows works fine in Hyper now.  Note that the names of some of the
selectors have changed to match the HTTP RFC ...

testUrlWithoutHostName
        | uri |
        uri := HyURI
                                fromStream: (ReadStream on: '/click?key1=v1&url=http://abc.com').
        self assert: uri scheme = 'http'.
        self assert: uri hostname isNil.
        self assert: uri portNumber = 80.
        self assert: uri path = '/click'.
        self assert: (uri queryAt: 'key1') = 'v1'.
        self assert: (uri queryAt: 'url') = 'http://abc.com'

I have included your test in the latest version of Hyper (c.f. the
Cincom public Store repository).  I'll credit you in the method
comment and the version notes.  Including your code in Swazoo
(including Hyper) will put it under the LGPL.  Let me know if that's
not OK and you would like me to remove it.

Thanks again.

All the best,
    Bruce

On 22/07/2008, Hwee-Boon Yar <[hidden email]> wrote:

> Hi,
>
>  First timer running Swazoo (2.1 on Squeak).
>
>  Following SUnit test case illustrates the problem (encoding
>  http://abc.com doesn't fix it):
>
>  testUrlWithoutHostName
>         | uri |
>         uri := SwazooURI fromString:'/click?key1=v1&url=http://abc.com'.
>         self assert: uri protocol = 'http'.
>         self assert: uri hostname isNil.   "This is parsed as abc.com"
>         self assert: uri port = 80.
>         self assert: uri identifier = '/click'.
>         self assert: (uri queryAt: 'key1') = 'v1'.
>         self assert: (uri queryAt: 'url') = 'http://abc.com'.
>
>  Any suggestion how to fix it? The SwazooURITest suggest the protocol
>  and hostname will always be around.. Thanks.
>
>  --
>  Hwee-Boon
>
>  -------------------------------------------------------------------------
>  This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
>  Build the coolest Linux based applications with Moblin SDK & win great prizes
>  Grand prize is a trip for two to an Open Source event anywhere in the world
>  http://moblin-contest.org/redirect.php?banner_id=100&url=/
>  _______________________________________________
>  Swazoo-devel mailing list
>  [hidden email]
>  https://lists.sourceforge.net/lists/listinfo/swazoo-devel
>


--
Make the most of your skills - with OpenSkills
http://www.openskills.org/

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Swazoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swazoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Error parsing URL when SwazooURI is passed a URL without protocol and hostname (e.g. /abc instead of http://xyz.com/abc)

Janko Mivšek
In reply to this post by Yar Hwee Boon-3
Hi Hwee-Boon Yar,

Hwee-Boon Yar wrote:

> First timer running Swazoo (2.1 on Squeak).

Welcome to Swazoo!

> Following SUnit test case illustrates the problem (encoding
> http://abc.com doesn't fix it):
>
> testUrlWithoutHostName
> | uri |
> uri := SwazooURI fromString:'/click?key1=v1&url=http://abc.com'.
> self assert: uri protocol = 'http'.
> self assert: uri hostname isNil.   "This is parsed as abc.com"
> self assert: uri port = 80.
> self assert: uri identifier = '/click'.
> self assert: (uri queryAt: 'key1') = 'v1'.
> self assert: (uri queryAt: 'url') = 'http://abc.com'.
>
> Any suggestion how to fix it? The SwazooURITest suggest the protocol
> and hostname will always be around.. Thanks.

Your test clearly shows that SwazooURI parser works incorrectly.
Have you time to improve it? I will then include your modifications into
next Swazoo version.

Best regards
Janko

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Swazoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swazoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Error parsing URL when SwazooURI is passed a URL without protocol and hostname (e.g. /abc instead of http://xyz.com/abc)

Yar Hwee Boon-3
In reply to this post by Bruce Badger
On Wed, Jul 23, 2008 at 4:58 PM, Bruce Badger <[hidden email]> wrote:

> Including your code in Swazoo
> (including Hyper) will put it under the LGPL.  Let me know if that's
> not OK and you would like me to remove it.

Go ahead, no problem.

--
Hwee-Boon

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Swazoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swazoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Error parsing URL when SwazooURI is passed a URL without protocol and hostname (e.g. /abc instead of http://xyz.com/abc)

Yar Hwee Boon-3
In reply to this post by Janko Mivšek
On Wed, Jul 23, 2008 at 5:18 PM, Janko Mivšek <[hidden email]> wrote:

>> Any suggestion how to fix it? The SwazooURITest suggest the protocol
>> and hostname will always be around.. Thanks.
>
> Your test clearly shows that SwazooURI parser works incorrectly.
> Have you time to improve it? I will then include your modifications into
> next Swazoo version.

Sure, shouldn't be a difficult fix, but as I mention SwazooURITest
seems to suggest the protocol and hostname are always around (that's
why it was not tested). What should be the assumption?

--
Hwee-Boon

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Swazoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swazoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Error parsing URL when SwazooURI is passed a URL without protocol and hostname (e.g. /abc instead of http://xyz.com/abc)

Janko Mivšek
Hwee-Boon Yar wrote:

> On Wed, Jul 23, 2008 at 5:18 PM, Janko Mivšek <[hidden email]> wrote:
>
>>> Any suggestion how to fix it? The SwazooURITest suggest the protocol
>>> and hostname will always be around.. Thanks.
>> Your test clearly shows that SwazooURI parser works incorrectly.
>> Have you time to improve it? I will then include your modifications into
>> next Swazoo version.
>
> Sure, shouldn't be a difficult fix, but as I mention SwazooURITest
> seems to suggest the protocol and hostname are always around (that's
> why it was not tested). What should be the assumption?

Results for parsing relative Url should be as your test suggests, IMHO.
So, http as default protocol, nil for hostname.

JAnko

>

--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Swazoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swazoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Error parsing URL when SwazooURI is passed a URL without protocol and hostname (e.g. /abc instead of http://xyz.com/abc)

Yar Hwee Boon-3
On Wed, Jul 23, 2008 at 5:52 PM, Janko Mivšek <[hidden email]> wrote:

> Results for parsing relative Url should be as your test suggests, IMHO.
> So, http as default protocol, nil for hostname.

Here it is. Passes the original tests and the new test. Note that it
still doesn't support if the URL is in the form of
'click?key1=v1&url=http://abc.com' (without the leading /). I guess
we'll know if that is a possible value when someone complains :)

=========
'From Squeak3.9.1 of 2 March 2008 [latest update: #7075] on 24 July
2008 at 1:32:49 am'!

!SwazooURI methodsFor: 'private' stamp: 'hboon 7/24/2008 01:32'!
readProtocolFrom: aStream
        "^self
        I read the protocol from the URI presumed to be in aStream. The
        protocol preceeds '://' in the URI. I leave the stream position either
        right after the '//' if there is a protocol, otherwise I reset the position
        to the start of the stream.
       
        A protocol should not have $? in it. This is used to detect cases where
        aStream represents something like '/click?key1=v1&url=http://abc.com'.
        Browse for #testUrlWithoutHostName."
        | candidateProtocol |
        candidateProtocol := aStream upTo: $:.
        (aStream size - aStream position >= 2
                        and: [aStream next == $/
                                        and: [aStream next == $/
                                                and: [(candidateProtocol includes: $?) not]]])
                ifTrue: [self protocol: candidateProtocol]
                ifFalse: [aStream reset]! !

==========

--
Hwee-Boon

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Swazoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swazoo-devel