1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

second pass at fixing #63336, using Joel Young final patch. looks okay.

* uri.c: second pass at fixing #63336, using Joel Young
  final patch. looks okay.
Daniel
This commit is contained in:
Daniel Veillard
2001-10-30 09:47:47 +00:00
parent bb6808ea16
commit 4def3bd94c
2 changed files with 171 additions and 143 deletions

View File

@ -1,3 +1,8 @@
Tue Oct 30 10:46:12 CET 2001 Daniel Veillard <daniel@veillard.com>
* uri.c: second pass at fixing #63336, using Joel Young
final patch. looks okay.
Tue Oct 30 00:56:05 CET 2001 Daniel Veillard <daniel@veillard.com> Tue Oct 30 00:56:05 CET 2001 Daniel Veillard <daniel@veillard.com>
* uri.c include/libxml/uri.h: trying to clear #63336 * uri.c include/libxml/uri.h: trying to clear #63336

103
uri.c
View File

@ -936,7 +936,8 @@ xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) {
* - Carl Douglas * - Carl Douglas
*/ */
xmlChar * xmlChar *
xmlURIEscape(const xmlChar *str) { xmlURIEscape(const xmlChar * str)
{
xmlChar *ret, *segment = NULL; xmlChar *ret, *segment = NULL;
xmlURIPtr uri; xmlURIPtr uri;
int ret2; int ret2;
@ -951,8 +952,11 @@ xmlURIEscape(const xmlChar *str) {
uri = xmlCreateURI(); uri = xmlCreateURI();
if (uri != NULL) { if (uri != NULL) {
/*
* Allow escaping errors in the unescaped form
*/
uri->cleanup = 1; uri->cleanup = 1;
ret2 = xmlParseURIReference(uri, str); ret2 = xmlParseURIReference(uri, (const char *)str);
if (ret2) { if (ret2) {
xmlFreeURI(uri); xmlFreeURI(uri);
return (NULL); return (NULL);
@ -967,74 +971,77 @@ xmlURIEscape(const xmlChar *str) {
if (uri->scheme) { if (uri->scheme) {
segment = xmlURIEscapeStr(BAD_CAST uri->scheme, BAD_CAST "+-."); segment = xmlURIEscapeStr(BAD_CAST uri->scheme, BAD_CAST "+-.");
NULLCHK(segment) NULLCHK(segment)
xmlStrcat(ret, segment); ret = xmlStrcat(ret, segment);
xmlStrcat(ret, BAD_CAST ":"); ret = xmlStrcat(ret, BAD_CAST ":");
xmlFree(segment); xmlFree(segment);
} }
if (uri->authority) { if (uri->authority) {
segment = xmlURIEscapeStr( BAD_CAST uri->authority, BAD_CAST "/?;:@"); segment =
xmlURIEscapeStr(BAD_CAST uri->authority, BAD_CAST "/?;:@");
NULLCHK(segment) NULLCHK(segment)
xmlStrcat(ret, BAD_CAST "//"); ret = xmlStrcat(ret, BAD_CAST "//");
xmlStrcat(ret, segment); ret = xmlStrcat(ret, segment);
xmlFree(segment); xmlFree(segment);
} }
if (uri->user) { if (uri->user) {
segment = xmlURIEscapeStr(BAD_CAST uri->user, BAD_CAST ";:&=+$,"); segment = xmlURIEscapeStr(BAD_CAST uri->user, BAD_CAST ";:&=+$,");
NULLCHK(segment) NULLCHK(segment)
xmlStrcat(ret, segment); ret = xmlStrcat(ret, segment);
xmlStrcat(ret, BAD_CAST "@"); ret = xmlStrcat(ret, BAD_CAST "@");
xmlFree(segment); xmlFree(segment);
} }
if (uri->server) { if (uri->server) {
segment = xmlURIEscapeStr(BAD_CAST uri->server, BAD_CAST "/?;:@"); segment = xmlURIEscapeStr(BAD_CAST uri->server, BAD_CAST "/?;:@");
NULLCHK(segment) NULLCHK(segment)
xmlStrcat(ret, BAD_CAST "//"); ret = xmlStrcat(ret, BAD_CAST "//");
xmlStrcat(ret, segment); ret = xmlStrcat(ret, segment);
xmlFree(segment); xmlFree(segment);
} }
if (uri->port) { if (uri->port) {
xmlChar port[10]; xmlChar port[10];
snprintf((char *) segment, 10, "%d", uri->port); snprintf((char *) segment, 10, "%d", uri->port);
xmlStrcat(ret, BAD_CAST ":"); ret = xmlStrcat(ret, BAD_CAST ":");
xmlStrcat(ret, port); ret = xmlStrcat(ret, port);
xmlFree(segment); xmlFree(segment);
} }
if (uri->path) { if (uri->path) {
segment = xmlURIEscapeStr( BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;"); segment =
xmlURIEscapeStr(BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;");
NULLCHK(segment) NULLCHK(segment)
xmlStrcat(ret, segment); ret = xmlStrcat(ret, segment);
xmlFree(segment); xmlFree(segment);
} }
if (uri->query) { if (uri->query) {
segment = xmlURIEscapeStr( BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$"); segment =
xmlURIEscapeStr(BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$");
NULLCHK(segment) NULLCHK(segment)
xmlStrcat(ret, BAD_CAST "?"); ret = xmlStrcat(ret, BAD_CAST "?");
xmlStrcat(ret, segment); ret = xmlStrcat(ret, segment);
xmlFree(segment); xmlFree(segment);
} }
if (uri->opaque) { if (uri->opaque) {
segment = xmlURIEscapeStr(BAD_CAST uri->opaque, BAD_CAST ""); segment = xmlURIEscapeStr(BAD_CAST uri->opaque, BAD_CAST "");
NULLCHK(segment) NULLCHK(segment)
xmlStrcat(ret, segment); ret = xmlStrcat(ret, segment);
xmlStrcat(ret, BAD_CAST ":"); ret = xmlStrcat(ret, BAD_CAST ":");
xmlFree(segment); xmlFree(segment);
} }
if (uri->fragment) { if (uri->fragment) {
segment = xmlURIEscapeStr(BAD_CAST uri->fragment, BAD_CAST "#"); segment = xmlURIEscapeStr(BAD_CAST uri->fragment, BAD_CAST "#");
NULLCHK(segment) NULLCHK(segment)
xmlStrcat(ret, BAD_CAST "#"); ret = xmlStrcat(ret, BAD_CAST "#");
xmlStrcat(ret, segment); ret = xmlStrcat(ret, segment);
xmlFree(segment); xmlFree(segment);
} }
#undef NULLCHK #undef NULLCHK
return (ret); return (ret);
@ -1059,14 +1066,18 @@ xmlURIEscape(const xmlChar *str) {
* Returns 0 or the error code * Returns 0 or the error code
*/ */
static int static int
xmlParseURIFragment(xmlURIPtr uri, const char **str) { xmlParseURIFragment(xmlURIPtr uri, const char **str)
{
const char *cur = *str; const char *cur = *str;
if (str == NULL) return(-1); if (str == NULL)
return (-1);
while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) NEXT(cur); while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
NEXT(cur);
if (uri != NULL) { if (uri != NULL) {
if (uri->fragment != NULL) xmlFree(uri->fragment); if (uri->fragment != NULL)
xmlFree(uri->fragment);
uri->fragment = xmlURIUnescapeString(*str, cur - *str, NULL); uri->fragment = xmlURIUnescapeString(*str, cur - *str, NULL);
} }
*str = cur; *str = cur;
@ -1085,14 +1096,18 @@ xmlParseURIFragment(xmlURIPtr uri, const char **str) {
* Returns 0 or the error code * Returns 0 or the error code
*/ */
static int static int
xmlParseURIQuery(xmlURIPtr uri, const char **str) { xmlParseURIQuery(xmlURIPtr uri, const char **str)
{
const char *cur = *str; const char *cur = *str;
if (str == NULL) return(-1); if (str == NULL)
return (-1);
while (IS_URIC(cur)) NEXT(cur); while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
NEXT(cur);
if (uri != NULL) { if (uri != NULL) {
if (uri->query != NULL) xmlFree(uri->query); if (uri->query != NULL)
xmlFree(uri->query);
uri->query = xmlURIUnescapeString(*str, cur - *str, NULL); uri->query = xmlURIUnescapeString(*str, cur - *str, NULL);
} }
*str = cur; *str = cur;
@ -1143,7 +1158,8 @@ xmlParseURIScheme(xmlURIPtr uri, const char **str) {
* Returns 0 or the error code * Returns 0 or the error code
*/ */
static int static int
xmlParseURIOpaquePart(xmlURIPtr uri, const char **str) { xmlParseURIOpaquePart(xmlURIPtr uri, const char **str)
{
const char *cur; const char *cur;
if (str == NULL) if (str == NULL)
@ -1154,9 +1170,11 @@ xmlParseURIOpaquePart(xmlURIPtr uri, const char **str) {
return (3); return (3);
} }
NEXT(cur); NEXT(cur);
while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) NEXT(cur); while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
NEXT(cur);
if (uri != NULL) { if (uri != NULL) {
if (uri->opaque != NULL) xmlFree(uri->opaque); if (uri->opaque != NULL)
xmlFree(uri->opaque);
uri->opaque = xmlURIUnescapeString(*str, cur - *str, NULL); uri->opaque = xmlURIUnescapeString(*str, cur - *str, NULL);
} }
*str = cur; *str = cur;
@ -1319,20 +1337,23 @@ host_done:
* Returns 0 or the error code * Returns 0 or the error code
*/ */
static int static int
xmlParseURIRelSegment(xmlURIPtr uri, const char **str) { xmlParseURIRelSegment(xmlURIPtr uri, const char **str)
{
const char *cur; const char *cur;
if (str == NULL) if (str == NULL)
return (-1); return (-1);
cur = *str; cur = *str;
if (!IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) { if (!(IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))) {
return (3); return (3);
} }
NEXT(cur); NEXT(cur);
while (IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) NEXT(cur); while (IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
NEXT(cur);
if (uri != NULL) { if (uri != NULL) {
if (uri->path != NULL) xmlFree(uri->path); if (uri->path != NULL)
xmlFree(uri->path);
uri->path = xmlURIUnescapeString(*str, cur - *str, NULL); uri->path = xmlURIUnescapeString(*str, cur - *str, NULL);
} }
*str = cur; *str = cur;
@ -1354,7 +1375,8 @@ xmlParseURIRelSegment(xmlURIPtr uri, const char **str) {
* Returns 0 or the error code * Returns 0 or the error code
*/ */
static int static int
xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash) { xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash)
{
const char *cur; const char *cur;
if (str == NULL) if (str == NULL)
@ -1370,7 +1392,8 @@ xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash) {
while (IS_PCHAR(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) while (IS_PCHAR(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
NEXT(cur); NEXT(cur);
} }
if (*cur != '/') break; if (*cur != '/')
break;
cur++; cur++;
} while (1); } while (1);
if (uri != NULL) { if (uri != NULL) {