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

Johann Richard pointed out some XPointer problems for URN based URI

* uri.c: Johann Richard pointed out some XPointer problems for
  URN based URI references in XInclude. Modified the URI parsing
  and saving routines to allow correct parsing and saving of
  XPointers, especially when attached to "opaque" scheme accordingly
  to RFC 2396
Daniel
This commit is contained in:
Daniel Veillard
2002-11-28 11:55:38 +00:00
parent 8db67d2704
commit fdd27d2718
2 changed files with 42 additions and 44 deletions

78
uri.c
View File

@ -285,16 +285,6 @@ xmlSaveUri(xmlURIPtr uri) {
ret[len++] = lo + (lo > 9? 'A'-10 : '0');
}
}
if (len >= max) {
max *= 2;
ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
if (ret == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n");
return(NULL);
}
}
ret[len++] = 0;
} else {
if (uri->server != NULL) {
if (len + 3 >= max) {
@ -488,7 +478,21 @@ xmlSaveUri(xmlURIPtr uri) {
}
}
}
if (uri->fragment != NULL) {
}
if (uri->fragment != NULL) {
if (len + 3 >= max) {
max *= 2;
ret = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar));
if (ret == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n");
return(NULL);
}
}
ret[len++] = '#';
p = uri->fragment;
while (*p != 0) {
if (len + 3 >= max) {
max *= 2;
ret = (xmlChar *) xmlRealloc(ret,
@ -499,41 +503,27 @@ xmlSaveUri(xmlURIPtr uri) {
return(NULL);
}
}
ret[len++] = '#';
p = uri->fragment;
while (*p != 0) {
if (len + 3 >= max) {
max *= 2;
ret = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar));
if (ret == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n");
return(NULL);
}
}
if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
ret[len++] = *p++;
else {
int val = *(unsigned char *)p++;
int hi = val / 0x10, lo = val % 0x10;
ret[len++] = '%';
ret[len++] = hi + (hi > 9? 'A'-10 : '0');
ret[len++] = lo + (lo > 9? 'A'-10 : '0');
}
if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
ret[len++] = *p++;
else {
int val = *(unsigned char *)p++;
int hi = val / 0x10, lo = val % 0x10;
ret[len++] = '%';
ret[len++] = hi + (hi > 9? 'A'-10 : '0');
ret[len++] = lo + (lo > 9? 'A'-10 : '0');
}
}
if (len >= max) {
max *= 2;
ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
if (ret == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n");
return(NULL);
}
}
ret[len++] = 0;
}
if (len >= max) {
max *= 2;
ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
if (ret == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n");
return(NULL);
}
}
ret[len++] = 0;
return(ret);
}
@ -1074,7 +1064,7 @@ xmlParseURIFragment(xmlURIPtr uri, const char **str)
if (str == NULL)
return (-1);
while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
while (IS_URIC(cur) || IS_UNWISE(cur))
NEXT(cur);
if (uri != NULL) {
if (uri->fragment != NULL)