diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2001-05-25 07:38:41 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2001-05-25 07:38:41 +0000 |
commit | 6278fb5b30821c9edc7b4304619944d2f50a932b (patch) | |
tree | 3fbf16a4d29cc96b6910b8ccbbe4b7792a47ea3a /uri.c | |
parent | d16df9f6efe5c0a4f41f4b3e60312c3f584659a5 (diff) | |
download | android_external_libxml2-6278fb5b30821c9edc7b4304619944d2f50a932b.tar.gz android_external_libxml2-6278fb5b30821c9edc7b4304619944d2f50a932b.tar.bz2 android_external_libxml2-6278fb5b30821c9edc7b4304619944d2f50a932b.zip |
- Makefile.am include/Makefile.am: small change to have
include/libxml rebuilt if working from CVS.
- uri.c: applied another patch from Carl Douglas for URI escaping,
this should close bug #51876
Daniel
Diffstat (limited to 'uri.c')
-rw-r--r-- | uri.c | 97 |
1 files changed, 91 insertions, 6 deletions
@@ -1051,17 +1051,102 @@ xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) { * It will try to escape the chars needing this, but this is heuristic * based it's impossible to be sure. * - * TODO: make the proper implementation of this function by calling - * xmlParseURIReference() and escaping each section accordingly - * to the rules (c.f. bug 51876) - * * Returns an copy of the string, but escaped + * + * 25 May 2001 + * Uses xmlParseURI and xmlURIEscapeStr to try to escape correctly + * according to RFC2396. + * - Carl Douglas */ xmlChar * xmlURIEscape(const xmlChar *str) { - xmlChar *ret; + xmlChar *ret, *segment = NULL; + xmlURIPtr uri; + +#define NULLCHK(p) if(!p) { \ + xmlGenericError(xmlGenericErrorContext, \ + "xmlURIEscape: out of memory\n"); \ + return NULL; } + + uri = xmlParseURI( (const char *) str); + + if(!uri) + return NULL; + + ret = NULL; + + if(uri->scheme) { + segment = xmlURIEscapeStr( BAD_CAST uri->scheme, BAD_CAST "+-."); + NULLCHK(segment) + xmlStrcat(ret, segment); + xmlStrcat(ret, BAD_CAST ":"); + xmlFree(segment); + } + + if(uri->authority) { + segment = xmlURIEscapeStr( BAD_CAST uri->authority, BAD_CAST "/?;:@"); + NULLCHK(segment) + xmlStrcat(ret, BAD_CAST "//"); + xmlStrcat(ret, segment); + xmlFree(segment); + } + + if(uri->user) { + segment = xmlURIEscapeStr( BAD_CAST uri->user, BAD_CAST ";:&=+$,"); + NULLCHK(segment) + xmlStrcat(ret, segment); + xmlStrcat(ret, BAD_CAST "@"); + xmlFree(segment); + } + + if(uri->server) { + segment = xmlURIEscapeStr( BAD_CAST uri->server, BAD_CAST "/?;:@"); + NULLCHK(segment) + xmlStrcat(ret, BAD_CAST "//"); + xmlStrcat(ret, segment); + xmlFree(segment); + } + + if(uri->port) { + xmlChar port[10]; + snprintf(segment, 10, "%d", uri->port); + xmlStrcat(ret, BAD_CAST ":"); + xmlStrcat(ret, port); + xmlFree(segment); + } + + if(uri->path) { + segment = xmlURIEscapeStr( BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;"); + NULLCHK(segment) + xmlStrcat(ret, segment); + xmlFree(segment); + } + + if(uri->query) { + segment = xmlURIEscapeStr( BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$"); + NULLCHK(segment) + xmlStrcat(ret, BAD_CAST "?"); + xmlStrcat(ret, segment); + xmlFree(segment); + } + + if(uri->opaque) { + segment = xmlURIEscapeStr( BAD_CAST uri->opaque, BAD_CAST ""); + NULLCHK(segment) + xmlStrcat(ret, segment); + xmlStrcat(ret, BAD_CAST ":"); + xmlFree(segment); + } + + if(uri->fragment) { + segment = xmlURIEscapeStr( BAD_CAST uri->fragment, BAD_CAST "#"); + NULLCHK(segment) + xmlStrcat(ret, BAD_CAST "#"); + xmlStrcat(ret, segment); + xmlFree(segment); + } - ret = xmlURIEscapeStr(str, BAD_CAST "#"); +#undef NULLCHK return(ret); } |