[BUG] String asURL fails

Lex Spoon lex at cc.gatech.edu
Thu Mar 7 06:42:00 UTC 2002


Dan Ingalls <Dan at SqueakLand.org> wrote:
> I get an error from 
> 
> 	'Macintosh HD:Fun with 3.2:Squeak.15.gif' asUrl
> 
> in Squeak as of #4795.
> 
> Michael produced a work-around so I could open this file, but presumably asURL should be fixed.
> 

Okay, the attached changeset should do what you need.  Instead of using
#asUrl, you can then do this:

	FileUrl fromFileName: 'Macintosh HD:Fun with 3.2:Squeak.15.gif'

I can't test on a Mac, but this changeset should at least be very close.
 You'll have to change the #asUrl to this new selector, but hopefully
that's okay.

Anyone who wants to know more can read onward.  But it's about the
workings of the grodie World Wide Web.  The innocent and the pure of
heart may wish to stop here.



|
|
|
|
|
|
|
|
|
|
|
|


purity maintenance space

|
|
|
|
|
|||
|
|
|
|
||
|
|




Okay, the root issue is that this isn't a valid URL.  (What?  Yes, it's
true.  If this grosses you out already, then maybe you should have
heeded the purity space.)  The proper format would be:

	'file:/Macintosh HD/Fun with 3.2/Squeak.15.gif'

(This must look really ugly to a Mac user.)  Focus mind over stomache, and
notice in particular that:

	1. It begins with 'file:' .

	2. It uses $/ instead of $: or $\, regardless of the platform.

	3. It starts an absolute path name with the $/ delimiter, even on a
Mac.


One idea here is that this format works on all platforms.  Thus, the U
in URL, for "universal".  Another idea is that the same format can be
used for http, gopher, telnet, mail, or whatever else-- the initial
'file:' is a whole bunch of tag bits.  URL's are actually a pretty
decent idea.  It's even been argued that URL's are the prettiest part of
the WWW.... whoops, sorry, I said "pretty" and "WWW" in the same
sentense.  Approach this thought carefully, lest it overwhelm you with
revolsion.  There's no rush.  Even the WWW can have one or two nice
ide---whoops, sorry, I'll stop.


Now, some might be wondering why #asUrl doesn't just deal with all of
this.  Web browsers do it, right?  And that thing is obviously a file
for a Macintosh, right?  The issue is that you can't always guess right.
 Here's a nasty example:

	'win.com'

Is this the FILE named win.com in the current directory, or the HTTP
server named win.com ?  Either answer could be correct.


We don't have to guess.  If we simply call a method like
#asUrlFromFilename instead of just #asUrl, then the system will know it
is a filename.  The invoked method will be able to do the Right Thing in
all cases, and there will be no ambiguity.


-Lex

PS -- it has been suggested before that Filename would be a good class
to have around.  It would certainly be useful here!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: /home/lex/squeak/fileNameToUrl.1.cs
Type: application/octet-stream
Size: 729 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20020307/1a2d8496/fileNameToUrl.1.obj


More information about the Squeak-dev mailing list