- uri.[ch]: applied a patch from Carl Douglas for URI escaping,

related to bug #51876
Daniel
This commit is contained in:
Daniel Veillard 2001-05-23 10:29:12 +00:00
parent 42596ad20c
commit 8514c674b2
4 changed files with 48 additions and 16 deletions

View File

@ -1,3 +1,8 @@
Wed May 23 12:27:44 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* uri.[ch]: applied a patch from Carl Douglas for URI escaping,
related to bug #51876
Tue May 22 18:46:56 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* tree.c: fixed a gross mistake in base computation, xml:base is

View File

@ -51,6 +51,8 @@ int xmlParseURIReference (xmlURIPtr uri,
xmlChar * xmlSaveUri (xmlURIPtr uri);
void xmlPrintURI (FILE *stream,
xmlURIPtr uri);
xmlChar * xmlURIEscapeStr (const xmlChar *str,
const xmlChar *list);
char * xmlURIUnescapeString (const char *str,
int len,
char *target);

55
uri.c
View File

@ -977,23 +977,20 @@ xmlURIUnescapeString(const char *str, int len, char *target) {
}
/**
* xmlURIEscape:
* @str: the string of the URI to escape
* xmlURIEscapeStr:
* @str: string to escape
* @list: exception list string of chars not to escape
*
* Escaping routine, does not do validity checks !
* It will try to escape the chars needing this, but this is heuristic
* based it's impossible to be sure.
* This routine escapes a string to hex, ignoring reserved characters (a-z)
* and the characters in the exception list.
*
* 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
* Returns a new escaped string or NULL in case of error.
*/
xmlChar *
xmlURIEscape(const xmlChar *str) {
xmlChar *ret;
xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) {
xmlChar *ret, ch;
const xmlChar *in;
unsigned int len, out;
if (str == NULL)
@ -1020,16 +1017,18 @@ xmlURIEscape(const xmlChar *str) {
return(NULL);
}
}
if ((!IS_UNRESERVED(*in)) && (*in != ':') && (*in != '/') &&
(*in != '?') && (*in != '#')) {
ch = *in;
if ( (!IS_UNRESERVED(ch)) && (!xmlStrchr(list, ch)) ) {
unsigned char val;
ret[out++] = '%';
val = *in >> 4;
val = ch >> 4;
if (val <= 9)
ret[out++] = '0' + val;
else
ret[out++] = 'A' + val - 0xA;
val = *in & 0xF;
val = ch & 0xF;
if (val <= 9)
ret[out++] = '0' + val;
else
@ -1038,11 +1037,35 @@ xmlURIEscape(const xmlChar *str) {
} else {
ret[out++] = *in++;
}
}
ret[out] = 0;
return(ret);
}
/**
* xmlURIEscape:
* @str: the string of the URI to escape
*
* Escaping routine, does not do validity checks !
* 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
*/
xmlChar *
xmlURIEscape(const xmlChar *str) {
xmlChar *ret;
ret = xmlURIEscapeStr(str, BAD_CAST "#");
return(ret);
}
/************************************************************************
* *
* Escaped URI parsing *

2
uri.h
View File

@ -51,6 +51,8 @@ int xmlParseURIReference (xmlURIPtr uri,
xmlChar * xmlSaveUri (xmlURIPtr uri);
void xmlPrintURI (FILE *stream,
xmlURIPtr uri);
xmlChar * xmlURIEscapeStr (const xmlChar *str,
const xmlChar *list);
char * xmlURIUnescapeString (const char *str,
int len,
char *target);