Index: uri.c @@ -1470,6 +1470,10 @@ /* * 1) The URI reference is parsed into the potential four components and * fragment identifier, as described in Section 4.3. + * + * NOTE that a completely empty URI is treated by modern browsers + * as a reference to "." rather than as a synonym for the current + * URI. Should we do that here? */ ref = xmlCreateURI(); if (ref == NULL) @@ -1489,29 +1493,45 @@ /* * 2) If the path component is empty and the scheme, authority, and * query components are undefined, then it is a reference to the - * current document. However, since we need to inherit these - * values from the base, we keep on going. + * current document and we are done. Otherwise, the reference URI's + * query and fragment components are defined as found (or not found) + * within the URI reference and not inherited from the base URI. * - * NOTE: this is a divergence from the RFC which says: - * current document and we are done. Otherwise, the reference URI's - * query and fragment components are defined as found (or not found) - * within the URI reference and not inherited from the base URI. + * NOTE that in modern browsers, the parsing differs from the above + * in the following aspect: the query component is allowed to be + * defined while still treating this as a reference to the current + * document. */ res = xmlCreateURI(); if (res == NULL) goto done; -#if 0 if ((ref->scheme == NULL) && (ref->path == NULL) && - ((ref->authority == NULL) && (ref->server == NULL)) && - (ref->query == NULL)) { - if (ref->fragment == NULL) - goto done; - res->fragment = xmlMemStrdup(ref->fragment); - val = xmlSaveUri(res); - goto done; + ((ref->authority == NULL) && (ref->server == NULL))) { + if (bas->scheme != NULL) + res->scheme = xmlMemStrdup(bas->scheme); + if (bas->authority != NULL) + res->authority = xmlMemStrdup(bas->authority); + else if (bas->server != NULL) { + res->server = xmlMemStrdup(bas->server); + if (bas->user != NULL) + res->user = xmlMemStrdup(bas->user); + res->port = bas->port; + } + if (bas->path != NULL) + res->path = xmlMemStrdup(bas->path); + if (ref->query != NULL) + res->query = xmlMemStrdup(ref->query); + else if (bas->query != NULL) + res->query = xmlMemStrdup(bas->query); + if (ref->fragment != NULL) + res->fragment = xmlMemStrdup(ref->fragment); + goto step_7; } -#endif + if (ref->query != NULL) + res->query = xmlMemStrdup(ref->query); + if (ref->fragment != NULL) + res->fragment = xmlMemStrdup(ref->fragment); /* * 3) If the scheme component is defined, indicating that the reference @@ -1544,10 +1564,6 @@ } if (ref->path != NULL) res->path = xmlMemStrdup(ref->path); - if (ref->query != NULL) - res->query = xmlMemStrdup(ref->query); - if (ref->fragment != NULL) - res->fragment = xmlMemStrdup(ref->fragment); goto step_7; } if (bas->authority != NULL) @@ -1562,32 +1578,9 @@ /* * 5) If the path component begins with a slash character ("/"), then * the reference is an absolute-path and we skip to step 7. - * - * If it is not defined, inherit the whole path from the base. - * The query and the fragment are inherited too, unless specified - * in the reference. - */ - if (ref->path == NULL) { - res->path = xmlMemStrdup(bas->path); - if (ref->query == NULL && ref->fragment == NULL) { - if (bas->query != NULL) - res->query = xmlMemStrdup(bas->query); - if (bas->fragment != NULL) - res->fragment = xmlMemStrdup(bas->fragment); - } else { - if (ref->query != NULL) - res->query = xmlMemStrdup(ref->query); - if (ref->fragment != NULL) - res->fragment = xmlMemStrdup(ref->fragment); - } - goto step_7; - } - if (ref->path[0] == '/') { + */ + if ((ref->path != NULL) && (ref->path[0] == '/')) { res->path = xmlMemStrdup(ref->path); - if (ref->query != NULL) - res->query = xmlMemStrdup(ref->query); - if (ref->fragment != NULL) - res->fragment = xmlMemStrdup(ref->fragment); goto step_7; } @@ -1658,11 +1651,6 @@ * Steps c) to h) are really path normalization steps */ xmlNormalizeURIPath(res->path); - - if (ref->query != NULL) - res->query = xmlMemStrdup(ref->query); - if (ref->fragment != NULL) - res->fragment = xmlMemStrdup(ref->fragment); step_7: