Re: A URL API

On Fri, Sep 17, 2010 at 11:16 AM, Darin Fisher <darin@chromium.org> wrote:
> On Fri, Sep 17, 2010 at 11:05 AM, Adam Barth <w3c@adambarth.com> wrote:
>> On Fri, Sep 17, 2010 at 10:27 AM, Adam Barth <w3c@adambarth.com> wrote:
>> > On Thu, Sep 16, 2010 at 3:25 PM, Darin Fisher <darin@chromium.org>
>> > wrote:
>> >> On Thu, Sep 16, 2010 at 6:31 AM, Julian Reschke <julian.reschke@gmx.de>
>> >> wrote:
>> >>> That sounds good to me. In general I think it would be great if there
>> >>> were
>> >>> standard APIs for URI/IRI construction, parsing and resolution...
>> >>
>> >> Yes, that sounds pretty good to me too.
>> >
>> > This has annoyed me for a while too.  I'll write up a spec.
>>
>> Here's a sketch:
>>
>> https://docs.google.com/document/edit?id=1r_VTFKApVOaNIkocrg0z-t7lZgzisTuGTXkdzAk4gLU&hl=en
>
> Nice!  Is there any implicit unescaping done when reading those members?
>  I'd hope for the answer to be "no" :-)

That's a good question.  I'd expect them to just be textual segments
of the URL so you could reconstruct the URL by concatenating them.

> When does canonicalization happen?  Only when you call href?  Or, does it
> happen when you readback any attribute?

I think it should happen when you read back any attribute.  That seems
safest from a security perspective since you're aways reading back
something canonical.

On Fri, Sep 17, 2010 at 11:16 AM, Nathan <nathan@webr3.org> wrote:
> might I suggest naming it URI or IRI, and the addition of some or all of the
> following methods:

I'd like to avoid bikeshedding about the name at this time.  We can
certainly discuss that in the future.

>  bool isAbsolute();
>  URI toAbsolute();

The interface will always represent an absolute URL.

>  URI defrag();

What does this mean?  If you mean "remove the fragment," you can do
that by assigning null to the hash property.

>  URI resolveReference(in URI reference);

You can do this with the constructor:

var resolved_url = new URL(relative_url, base_url);

> the following methods exposed to handle complicated URIs:
>
>  u = new URI('http://ex.org/a/b/c/d/../.././egg#s/../x');
>  u.isAbsolute();                        -> boolean
>  u.defrag();                            ->
> 'http://ex.org/a/b/c/d/../.././egg'
>  u.toAbsolute();                        -> 'http://ex.org/a/b/egg'
>
> and to resolve relative URIs + URI References:
>
>  u = new URI('http://ex.org/a/b/c/d');
>  u.resolveReference('../.././n?x=y');   -> 'http://ex.org/a/n?x=y'
>
> ps: I'll happily implement this interface Javascript whenever as I've
> already got something similar: http://github.com/webr3/URI

Thanks.  It would certainly be helpful to have a sample implementation
in JavaScript.

Adam

Received on Friday, 17 September 2010 18:37:30 UTC