Currently it is close, but not quite.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | resolve_url-3.patch | 15.44 KB | c960657 |
| #4 | resolve_url-2.patch | 15.49 KB | c960657 |
| #1 | resolve_url-1.patch | 10.96 KB | c960657 |
Currently it is close, but not quite.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | resolve_url-3.patch | 15.44 KB | c960657 |
| #4 | resolve_url-2.patch | 15.49 KB | c960657 |
| #1 | resolve_url-1.patch | 10.96 KB | c960657 |
Comments
Comment #1
c960657 commentedIt takes quite a lot of code to get it right, but I think it is useful also outside the browser, so I put it in common.inc.
The code is based on the implementation I did in Net_URL2::resolve() for PEARs Net_URL2 package.
Perhaps we can combine _drupal_parse_url() and valid_url() at some point.
Comment #2
joshmillerThis function no longer returns a string. It returns an array. This is an API breaker... which is banned post code freeze. May need to return a string to keep API intact.
This word isn't right, perhaps "Relative URLs are supported in addition to PHP's parse_url() typical usage."
This should be moved up into the comment head above the function.
just "return FALSE;" -- the 'else' is implied and wastes space.
@return?
@params?
Since we are dealing with user supplied input, all "==" should be "===" otherwise, we open ourselves up to some weird PHP false positives.
I don't understand the "Step 2.A" etc... BTW you have two "Step 2.A"s
needs "==="
needs "==="
needs "==="
I'm on crack. Are you, too?
Comment #3
hass commentedInteresting code...
Comment #4
c960657 commentedI upgraded _drupal_parse_url() to a public function, drupal_parse_url(), and made it return all keys returned by parse_url(), i.e. also "user", "pass", "host", "port" (note that "user" and "pass" are not mentioned in RFC 3986). I also added some tests and elaborated the Doxygen comment.
Huh? getAbsoluteUrl() still returns a string AFAICT, so no API break here.
The $base_parts and $relative_parts arrays are both returned by drupal_parse_url(), so the format is well known. In particular, drupal_parse_url() guarantees that $parts['path'] is always a string. Of course, using
===doesn't hurt, but I think we usually just use==.The implementation closely follows the recipe in the RFC, section 5.2.4. Step 2.A is split into two if-clauses and implements the following:
People wanting to mess with this code really should have the RFC handy, so I haven't copied the actual text from there into the comments.
Comment #5
c960657 commentedRemoved the "authority" and "userinfo" parts from drupal_parse_url() to make it more like parse_url().
Comment #7
boombatower commentedMove to Browser module for further development.