aboutsummaryrefslogtreecommitdiffstats
path: root/uri.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2001-05-23 10:29:12 +0000
committerDaniel Veillard <veillard@src.gnome.org>2001-05-23 10:29:12 +0000
commit8514c674b23e5053b6c2d54171b3406602c825af (patch)
tree464d359397d5814282dafd2ab3643d1f4938b212 /uri.c
parent42596ad20cdf1925dd79ea801cbe598b6e7b7aec (diff)
downloadandroid_external_libxml2-8514c674b23e5053b6c2d54171b3406602c825af.tar.gz
android_external_libxml2-8514c674b23e5053b6c2d54171b3406602c825af.tar.bz2
android_external_libxml2-8514c674b23e5053b6c2d54171b3406602c825af.zip
- uri.[ch]: applied a patch from Carl Douglas for URI escaping,
related to bug #51876 Daniel
Diffstat (limited to 'uri.c')
-rw-r--r--uri.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/uri.c b/uri.c
index 928c77ff..779ca6fc 100644
--- a/uri.c
+++ b/uri.c
@@ -977,23 +977,20 @@ xmlURIUnescapeString(const char *str, int len, char *target) {
}
/**
- * 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.
+ * xmlURIEscapeStr:
+ * @str: string to escape
+ * @list: exception list string of chars not to escape
*
- * TODO: make the proper implementation of this function by calling
- * xmlParseURIReference() and escaping each section accordingly
- * to the rules (c.f. bug 51876)
+ * This routine escapes a string to hex, ignoring reserved characters (a-z)
+ * and the characters in the exception list.
*
- * 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 *