The best way to construct a file/url path handling misplaced $/ chars

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

The best way to construct a file/url path handling misplaced $/ chars

Tim Mackinnon
I’m sure we have something in the image that deals with this - but if writing a generic http retriever and wanting to correctly cope with constructing resource paths where the base path may or may not have a trailing /, and the resource path may or may not have a leading /

Basically - magically handle

/name//resourse
/name///resource


I’m sure we have something simple - the best I could see was to abuse Path like:

(Path from: basePath, '/', resourcePath) pathString

Is this a good way to do it?

Tim
Reply | Threaded
Open this post in threaded view
|

Re: The best way to construct a file/url path handling misplaced $/ chars

cedreek
Not sure but I would use ZnUrl

ZnUrl new
                scheme: #http;
                host: NetNameResolver loopBackName;
                addPathSegments: #('echo' 'foo');
                yourself

Making sure Path segments do not contain separator…

Hth,

Cédrick



> Le 8 mars 2019 à 12:33, Tim Mackinnon <[hidden email]> a écrit :
>
> I’m sure we have something in the image that deals with this - but if writing a generic http retriever and wanting to correctly cope with constructing resource paths where the base path may or may not have a trailing /, and the resource path may or may not have a leading /
>
> Basically - magically handle
>
> /name//resourse
> /name///resource
>
>
> I’m sure we have something simple - the best I could see was to abuse Path like:
>
> (Path from: basePath, '/', resourcePath) pathString
>
> Is this a good way to do it?
>
> Tim


Reply | Threaded
Open this post in threaded view
|

Re: The best way to construct a file/url path handling misplaced $/ chars

cedreek
'/foo//' copyWithoutAll: '/'

> Le 8 mars 2019 à 12:40, Cédrick Béler <[hidden email]> a écrit :
>
> Not sure but I would use ZnUrl
>
> ZnUrl new
> scheme: #http;
> host: NetNameResolver loopBackName;
> addPathSegments: #('echo' 'foo');
> yourself
>
> Making sure Path segments do not contain separator…
>
> Hth,
>
> Cédrick
>
>
>
>> Le 8 mars 2019 à 12:33, Tim Mackinnon <[hidden email]> a écrit :
>>
>> I’m sure we have something in the image that deals with this - but if writing a generic http retriever and wanting to correctly cope with constructing resource paths where the base path may or may not have a trailing /, and the resource path may or may not have a leading /
>>
>> Basically - magically handle
>>
>> /name//resourse
>> /name///resource
>>
>>
>> I’m sure we have something simple - the best I could see was to abuse Path like:
>>
>> (Path from: basePath, '/', resourcePath) pathString
>>
>> Is this a good way to do it?
>>
>> Tim
>


Reply | Threaded
Open this post in threaded view
|

Re: The best way to construct a file/url path handling misplaced $/ chars

Esteban A. Maringolo
In reply to this post by Tim Mackinnon
I don't know whether you want to build just "paths" or valid URIs, if it's the latter, I'd suggest ZnUrl as well.

'/name/' asPath / 'resource'. -> /name/resource
'/name/' asPath / '/resource'. -> /resource (which is correct)

'/name/' asUrl / '/resource' -> /name//resource (which is correct as well).

The other way is to use path segments, as Cédrick suggested.

Regards,

Esteban A. Maringolo


El vie., 8 mar. 2019 a las 8:34, Tim Mackinnon (<[hidden email]>) escribió:
I’m sure we have something in the image that deals with this - but if writing a generic http retriever and wanting to correctly cope with constructing resource paths where the base path may or may not have a trailing /, and the resource path may or may not have a leading /

Basically - magically handle

/name//resourse
/name///resource


I’m sure we have something simple - the best I could see was to abuse Path like:

(Path from: basePath, '/', resourcePath) pathString

Is this a good way to do it?

Tim