Hi sven

thank you for the time you spent replying to me :)

Yes, this is confusing.

The first 2 forward slashed are part of the scheme, file:// or http://

Next comes the host:port, but that does not make too much sense for a File URL.

Finally comes the path.

For the syntax to make sense, you need a third / (to indicate that there is no host:port).

If you inspect the ZnUrl object in your second example, 'file://toto.png' asUrl, you will see that is has toto.png as host, not as path. This is in fact an invalid File URL.

The annoying thing is, there is no such thing as a relative File URL.

Yes I considered that a fully formed (with http as scheme) is always absolute. 

https://en.wikipedia.org/wiki/File_URI_scheme

Now, for your problem, I would not allow the use of file:// there, and just simpler file references (using #asFileReference), which can be relative.

Good suggestion I will do that. 


Sven

PS: Also, the methods #isAbsolute and #isRelative do not make much sense on ZnUrl, see the method comment/implementation.

I was experimenting more during a meeting :)


'figures/image.png' asFileReference asResolvedBy: FileSystem memory / 'docs' 
"memory:///docs/figures/image.png"

Which is what I want but this is for file reference. 
And file Reference are not polymorphic to url.

'figures/image.png' asUrl asFileReference 
asResolvedBy: FileSystem memory / 'docs' 

Do you think it would be possible to get the best of both worlds?

ZnUrl >> asFileReference
"Convert the receiver into a new FileReference object.
Note that for a FileReference a trailing slash is not relevant"

| path |
self assert: self scheme = #file description: 'Only a file:// URL can be converted to a FileReference'.
self isSlash
ifTrue: [ ^ FileSystem root ].
path := self isDirectoryPath
ifTrue: [ segments allButLast ]
ifFalse: [ segments copy ].
^ FileReference fileSystem: FileSystem disk path: (AbsolutePath withAll: path)


Removing the assert: would makes my life easier. 
Even if it returns an absolute path while 'figures/image.png��� is a relative one. 
Else I can copy and paste asFileReference and create my own. 

S

On 31 Aug 2021, at 16:11, Sven Van Caekenberghe <sven@stfx.eu> wrote:

Stef,

Yes, this is confusing.

The first 2 forward slashed are part of the scheme, file:// or http://

Next comes the host:port, but that does not make too much sense for a File URL.

Finally comes the path.

For the syntax to make sense, you need a third / (to indicate that there is no host:port).

If you inspect the ZnUrl object in your second example, 'file://toto.png' asUrl, you will see that is has toto.png as host, not as path. This is in fact an invalid File URL.

The annoying thing is, there is no such thing as a relative File URL.

https://en.wikipedia.org/wiki/File_URI_scheme

Now, for your problem, I would not allow the use of file:// there, and just simpler file references (using #asFileReference), which can be relative.

Sven

PS: Also, the methods #isAbsolute and #isRelative do not make much sense on ZnUrl, see the method comment/implementation.

On 31 Aug 2021, at 14:54, stephane ducasse <stephane.ducasse@inria.fr> wrote:

Hi

I���m a bit confused. When I use isAbsolute I get

'file:///toto.png' asUrl isAbsolute
false


'file://toto.png' asUrl isAbsolute
true


Now I confused because as Unix / is absolute so file://toto.png would be relative.
and /foo is absolute.

Are URLs so different than files?
Are the results I get correct?

I ask this question in the context of Microdown if people write

![caption](file://toto.png).
![caption](figures/toto.png)
![caption](file:///toto.png).

S