- uri.[ch]: applied a patch from Carl Douglas for URI escaping,
related to bug #51876
Daniel
diff --git a/ChangeLog b/ChangeLog
index d40fab6..940f8e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/include/libxml/uri.h b/include/libxml/uri.h
index 3d87e14..874151c 100644
--- a/include/libxml/uri.h
+++ b/include/libxml/uri.h
@@ -51,6 +51,8 @@
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);
diff --git a/uri.c b/uri.c
index 928c77f..779ca6f 100644
--- a/uri.c
+++ b/uri.c
@@ -977,23 +977,20 @@
}
/**
- * 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 @@
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 @@
} 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 *
diff --git a/uri.h b/uri.h
index 3d87e14..874151c 100644
--- a/uri.h
+++ b/uri.h
@@ -51,6 +51,8 @@
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);