mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-28 00:21:53 +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:
@ -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>
|
||||
|
||||
* uri.c include/libxml/uri.h: trying to clear #63336
|
||||
|
103
uri.c
103
uri.c
@ -936,7 +936,8 @@ xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) {
|
||||
* - Carl Douglas
|
||||
*/
|
||||
xmlChar *
|
||||
xmlURIEscape(const xmlChar *str) {
|
||||
xmlURIEscape(const xmlChar * str)
|
||||
{
|
||||
xmlChar *ret, *segment = NULL;
|
||||
xmlURIPtr uri;
|
||||
int ret2;
|
||||
@ -951,8 +952,11 @@ xmlURIEscape(const xmlChar *str) {
|
||||
|
||||
uri = xmlCreateURI();
|
||||
if (uri != NULL) {
|
||||
/*
|
||||
* Allow escaping errors in the unescaped form
|
||||
*/
|
||||
uri->cleanup = 1;
|
||||
ret2 = xmlParseURIReference(uri, str);
|
||||
ret2 = xmlParseURIReference(uri, (const char *)str);
|
||||
if (ret2) {
|
||||
xmlFreeURI(uri);
|
||||
return (NULL);
|
||||
@ -967,74 +971,77 @@ xmlURIEscape(const xmlChar *str) {
|
||||
if (uri->scheme) {
|
||||
segment = xmlURIEscapeStr(BAD_CAST uri->scheme, BAD_CAST "+-.");
|
||||
NULLCHK(segment)
|
||||
xmlStrcat(ret, segment);
|
||||
xmlStrcat(ret, BAD_CAST ":");
|
||||
ret = xmlStrcat(ret, segment);
|
||||
ret = xmlStrcat(ret, BAD_CAST ":");
|
||||
xmlFree(segment);
|
||||
}
|
||||
|
||||
if (uri->authority) {
|
||||
segment = xmlURIEscapeStr( BAD_CAST uri->authority, BAD_CAST "/?;:@");
|
||||
segment =
|
||||
xmlURIEscapeStr(BAD_CAST uri->authority, BAD_CAST "/?;:@");
|
||||
NULLCHK(segment)
|
||||
xmlStrcat(ret, BAD_CAST "//");
|
||||
xmlStrcat(ret, segment);
|
||||
ret = xmlStrcat(ret, BAD_CAST "//");
|
||||
ret = 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 "@");
|
||||
ret = xmlStrcat(ret, segment);
|
||||
ret = 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);
|
||||
ret = xmlStrcat(ret, BAD_CAST "//");
|
||||
ret = xmlStrcat(ret, segment);
|
||||
xmlFree(segment);
|
||||
}
|
||||
|
||||
if (uri->port) {
|
||||
xmlChar port[10];
|
||||
|
||||
snprintf((char *) segment, 10, "%d", uri->port);
|
||||
xmlStrcat(ret, BAD_CAST ":");
|
||||
xmlStrcat(ret, port);
|
||||
ret = xmlStrcat(ret, BAD_CAST ":");
|
||||
ret = xmlStrcat(ret, port);
|
||||
xmlFree(segment);
|
||||
}
|
||||
|
||||
if (uri->path) {
|
||||
segment = xmlURIEscapeStr( BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;");
|
||||
segment =
|
||||
xmlURIEscapeStr(BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;");
|
||||
NULLCHK(segment)
|
||||
xmlStrcat(ret, segment);
|
||||
ret = xmlStrcat(ret, segment);
|
||||
xmlFree(segment);
|
||||
}
|
||||
|
||||
if (uri->query) {
|
||||
segment = xmlURIEscapeStr( BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$");
|
||||
segment =
|
||||
xmlURIEscapeStr(BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$");
|
||||
NULLCHK(segment)
|
||||
xmlStrcat(ret, BAD_CAST "?");
|
||||
xmlStrcat(ret, segment);
|
||||
ret = xmlStrcat(ret, BAD_CAST "?");
|
||||
ret = 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 ":");
|
||||
ret = xmlStrcat(ret, segment);
|
||||
ret = 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);
|
||||
ret = xmlStrcat(ret, BAD_CAST "#");
|
||||
ret = xmlStrcat(ret, segment);
|
||||
xmlFree(segment);
|
||||
}
|
||||
|
||||
#undef NULLCHK
|
||||
|
||||
return (ret);
|
||||
@ -1059,14 +1066,18 @@ xmlURIEscape(const xmlChar *str) {
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
xmlParseURIFragment(xmlURIPtr uri, const char **str) {
|
||||
xmlParseURIFragment(xmlURIPtr uri, const char **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->fragment != NULL) xmlFree(uri->fragment);
|
||||
if (uri->fragment != NULL)
|
||||
xmlFree(uri->fragment);
|
||||
uri->fragment = xmlURIUnescapeString(*str, cur - *str, NULL);
|
||||
}
|
||||
*str = cur;
|
||||
@ -1085,14 +1096,18 @@ xmlParseURIFragment(xmlURIPtr uri, const char **str) {
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
xmlParseURIQuery(xmlURIPtr uri, const char **str) {
|
||||
xmlParseURIQuery(xmlURIPtr uri, const char **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->query != NULL) xmlFree(uri->query);
|
||||
if (uri->query != NULL)
|
||||
xmlFree(uri->query);
|
||||
uri->query = xmlURIUnescapeString(*str, cur - *str, NULL);
|
||||
}
|
||||
*str = cur;
|
||||
@ -1143,7 +1158,8 @@ xmlParseURIScheme(xmlURIPtr uri, const char **str) {
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
xmlParseURIOpaquePart(xmlURIPtr uri, const char **str) {
|
||||
xmlParseURIOpaquePart(xmlURIPtr uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
|
||||
if (str == NULL)
|
||||
@ -1154,9 +1170,11 @@ xmlParseURIOpaquePart(xmlURIPtr uri, const char **str) {
|
||||
return (3);
|
||||
}
|
||||
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->opaque != NULL) xmlFree(uri->opaque);
|
||||
if (uri->opaque != NULL)
|
||||
xmlFree(uri->opaque);
|
||||
uri->opaque = xmlURIUnescapeString(*str, cur - *str, NULL);
|
||||
}
|
||||
*str = cur;
|
||||
@ -1319,20 +1337,23 @@ host_done:
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
xmlParseURIRelSegment(xmlURIPtr uri, const char **str) {
|
||||
xmlParseURIRelSegment(xmlURIPtr uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
|
||||
if (str == NULL)
|
||||
return (-1);
|
||||
|
||||
cur = *str;
|
||||
if (!IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) {
|
||||
if (!(IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))) {
|
||||
return (3);
|
||||
}
|
||||
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->path != NULL) xmlFree(uri->path);
|
||||
if (uri->path != NULL)
|
||||
xmlFree(uri->path);
|
||||
uri->path = xmlURIUnescapeString(*str, cur - *str, NULL);
|
||||
}
|
||||
*str = cur;
|
||||
@ -1354,7 +1375,8 @@ xmlParseURIRelSegment(xmlURIPtr uri, const char **str) {
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash) {
|
||||
xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash)
|
||||
{
|
||||
const char *cur;
|
||||
|
||||
if (str == NULL)
|
||||
@ -1370,7 +1392,8 @@ xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash) {
|
||||
while (IS_PCHAR(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
|
||||
NEXT(cur);
|
||||
}
|
||||
if (*cur != '/') break;
|
||||
if (*cur != '/')
|
||||
break;
|
||||
cur++;
|
||||
} while (1);
|
||||
if (uri != NULL) {
|
||||
|
Reference in New Issue
Block a user