[whatwg] [URL] DOM API Feedback

Adam Barth w3c at adambarth.com
Thu Nov 8 17:58:24 PST 2012


On Thu, Nov 8, 2012 at 6:22 AM, Alex Russell <slightlyoff at google.com> wrote:
> Howdy all,
>
> Anne asked me to send feedback on the DOM API for the new URL spec (
> http://url.spec.whatwg.org/#api) to this list. Here goes:
>
> First, I love that this looks sane, like what you need most of the time,
> and will plumb through to the browser's parsing algorithm without requiring
> me to re-write this sort of thing (badly) every time I need it. +1 for
> adding a good DOM API!
>
> Next, nicely done on having a meaningful constructor! I do wonder if the
> "url" parameter should be optional as well as the base, since you may
> either want to build a URL using a URL object (to be serialized later).
>
> Looking at what URL/URLUtils provides, I noted a couple of things I'd like
> to see that I miss from
> google-url<http://code.google.com/p/google-url/source/browse/trunk/src/gurl.h>(a.k.a.
> "GURL", the URL library we use in Chrome):
>
>
>    - GetWithEmptyPath() & GetOrigin() (despite their terrible C++ naming)
>    are hugely useful for doing comparisons. I could imagine that there's some

http://url.spec.whatwg.org/#dom-url-origin is the equivalent to GURL's
GetOrigin().

>    - "username" and "password" properties are missing
>    - There aren't any provided comparison functions. I.e., there's no way
>    to tell if two URL objects reference the same absolute URL, if
>    one references a path in the same domain, etc.

The notion of "the same absolute URL" is a bit slippery.  It depends
on how well you understand various URL components (e.g., octal
encodings of IP addesss).  We could define something, of course, but
we'd just need to do so carefully.

>    - Is there any attempt to parse query parameters and/or return a form
>    data object from them?

Yes, the http://url.spec.whatwg.org/#urlquery interface lets you get
at parsed URL parameters.  I don't think there's currently a way to
turn them into form data objects, but that would make sense.

We might also want to add a bulk setter that takes a Dictionary.

> Also, what's the default base URL? If I'm in a document with a base set,
> are instances that don't specify one relative to the origin of the window
> object from which the instance is created? I ask, because in the caes of:
>
>     new URL("/thinger.html");
>
> I'd expect identical calls like that to have different toString() values if
> executed on foo.com and bar.com. It was unclear to me if that's the case
> today.

That's covered in step 1 of
<http://url.spec.whatwg.org/#constructors>.  If there's no explicit
base, the URL is resolved relative to about:blank.  To me, that seems
better that implicitly using the document's base URL.  You can always
supply the document's base URL from document.baseURI if you want.

Adam



More information about the whatwg mailing list