URL changes, the trailing slash is striking again

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

URL changes, the trailing slash is striking again

Michel Bany
Lukas,

Not sure if this has already been reported,
        (WAUrl new)
                addToPath: 'files';
                addToPath: 'basic.css';
                asString
gives
        '/files/basic.css/'

If the css stylesheet is refering to images in the same file library,  
then you need something ugly like this
        url(../bg.jpg)

Instead I am hacking this (ugly too but not as much) in  
WAUrl>>pathString for the trailing slash.
        (path last includes: $.) ifFalse: [stream nextPut: $/]

Cheers,
Michel.



Reply | Threaded
Open this post in threaded view
|

Re: URL changes, the trailing slash is striking again

Lukas Renggli
> Instead I am hacking this (ugly too but not as much) in
> WAUrl>>pathString for the trailing slash.
>         (path last includes: $.) ifFalse: [stream nextPut: $/]

I guess in this case it is better to restore the old code and not
depend on hacks that might or might not work:

WAUrl>>pathString
        ^ String streamContents: [ :stream |
                stream nextPut: $/.
                path
                        do: [ :each | stream nextPutAll: each ]
                        separatedBy: [ stream nextPut: $/ ] ]

We always have apache running anyway, so that it canrewrite the
tailing-slashes if necessary :-/

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

Reply | Threaded
Open this post in threaded view
|

Re: URL changes, the trailing slash is striking again

Lukas Renggli
> I guess in this case it is better to restore the old code and not
> depend on hacks that might or might not work:
>
> WAUrl>>pathString
>         ^ String streamContents: [ :stream |
>                 stream nextPut: $/.
>                 path
>                         do: [ :each | stream nextPutAll: each ]
>                         separatedBy: [ stream nextPut: $/ ] ]
>
> We always have apache running anyway, so that it canrewrite the
> tailing-slashes if necessary :-/

I just reverted that change in the latest version to the state it was
before I first touched it ;-)

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

Reply | Threaded
Open this post in threaded view
|

Re: URL changes, the trailing slash is striking again

Philippe Marschall
2007/2/15, Lukas Renggli <[hidden email]>:

> > I guess in this case it is better to restore the old code and not
> > depend on hacks that might or might not work:
> >
> > WAUrl>>pathString
> >         ^ String streamContents: [ :stream |
> >                 stream nextPut: $/.
> >                 path
> >                         do: [ :each | stream nextPutAll: each ]
> >                         separatedBy: [ stream nextPut: $/ ] ]
> >
> > We always have apache running anyway, so that it canrewrite the
> > tailing-slashes if necessary :-/
>
> I just reverted that change in the latest version to the state it was
> before I first touched it ;-)

Why don't we differentiate between directories in the path and the
(optional) file at the end of the path? Slashes only after the
authority and every directory in the path. Wouldn't that just solve
it?

Cheers
Philipe

Reply | Threaded
Open this post in threaded view
|

Re: URL changes, the trailing slash is striking again

Lex Spoon-3
In reply to this post by Michel Bany
Michel Bany <[hidden email]> writes:
> Not sure if this has already been reported,
> (WAUrl new)
> addToPath: 'files';
> addToPath: 'basic.css';
> asString
> gives
> '/files/basic.css/'


FWIW, the URL classes in the image handle this.  They were written
back in '98 and have been carefully updated since then as problems
come up.  The approach is that a trailing slash mean the last part
of the path is an empty string.  To continue with this example:

FileUrl pathParts: #('files' 'basic.css')
   "yields file:///files/basic.css"

FileUrl pathParts: #('files' 'basic.css' '')
   "yields file:///files/basic.css/"



It would seem prudent to try and use the standard classes if possible.
That way we will avoid these "striking again" problems that come from
reinventing everything all the time.

See also the various "TimeStamp" and "Timestamp" classes that keep
reinventing DateAndTime.  Overall, Smalltalkers inherit quite a large
legacy of cool utility code.


-Lex


Reply | Threaded
Open this post in threaded view
|

Re: URL changes, the trailing slash is striking again

Lukas Renggli
> FWIW, the URL classes in the image handle this.  They were written
> back in '98 and have been carefully updated since then as problems
> come up.  The approach is that a trailing slash mean the last part
> of the path is an empty string.  To continue with this example:
>
> FileUrl pathParts: #('files' 'basic.css')
>    "yields file:///files/basic.css"
>
> FileUrl pathParts: #('files' 'basic.css' '')
>    "yields file:///files/basic.css/"

Interesting, I didn't know that these existed. What they are used for?
What is the difference to FileDirectory? HTTPSocket, KomServer and
friends doesn't seem to use them.

Another thing is that Seaside is nowadays regularly ported to other
dialects (and potentially to more). Using Squeak specific code makes
this more difficult.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

Reply | Threaded
Open this post in threaded view
|

Re: URL changes, the trailing slash is striking again

Lex Spoon-3
"Lukas Renggli" <[hidden email]> writes:

> > FWIW, the URL classes in the image handle this.  They were written
> > back in '98 and have been carefully updated since then as problems
> > come up.  The approach is that a trailing slash mean the last part
> > of the path is an empty string.  To continue with this example:
> >
> > FileUrl pathParts: #('files' 'basic.css')
> >    "yields file:///files/basic.css"
> >
> > FileUrl pathParts: #('files' 'basic.css' '')
> >    "yields file:///files/basic.css/"
>
> Interesting, I didn't know that these existed. What they are used for?
> What is the difference to FileDirectory? HTTPSocket, KomServer and
> friends doesn't seem to use them.


They are the built-in URL classes of Squeak, no more nor less.

Scamper and Celeste use them, and they themselves use HTTPSocket for
downloading http:// url's.  For the others in your list, IMHO
ServerDirectory might benefit from them, and I don't know whether
KomServer actually processes any URL's.  If it does, then maybe they
could help KomServer, too.


They also make for cute one-liners.  :)  Googling turned
up this one:

  (HtmlParser parse: 'http://www.squeak.org/' asUrl
       retrieveContents content) explore


http://wiki.squeak.org/squeak/1395


-Lex