aboutsummaryrefslogtreecommitdiff
path: root/iri.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-02-07 18:55:04 +0000
committerOmar Polo <op@omarpolo.com>2021-02-07 18:55:04 +0000
commit9f006a2127398af12ecf9159cd5ef28b3685e7a6 (patch)
tree5c9690dc757ae7b29c8b14ea391a6f252837de3f /iri.c
parenta13739138b17a21dbb50011cc65fb135e9f804c8 (diff)
[cgi] split the query in words if needed and add them to the argv
Diffstat (limited to 'iri.c')
-rw-r--r--iri.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/iri.c b/iri.c
index 1d550ef..b911b0d 100644
--- a/iri.c
+++ b/iri.c
@@ -75,6 +75,13 @@ valid_pct_encoded(struct parser *p)
return 1;
}
+static void
+pct_decode(char *s)
+{
+ sscanf(s+1, "%2hhx", s);
+ memmove(s+1, s+3, strlen(s+3)+1);
+}
+
static int
parse_pct_encoded(struct parser *p)
{
@@ -86,8 +93,7 @@ parse_pct_encoded(struct parser *p)
return 0;
}
- sscanf(p->iri+1, "%2hhx", p->iri);
- memmove(p->iri+1, p->iri+3, strlen(p->iri+3)+1);
+ pct_decode(p->iri);
if (*p->iri == '\0') {
p->err = "illegal percent-encoding";
return 0;
@@ -437,3 +443,16 @@ serialize_iri(struct iri *i, char *buf, size_t len)
return l < len;
}
+
+char *
+pct_decode_str(char *s)
+{
+ char *t;
+
+ for (t = s; *t; ++t) {
+ if (*t == '%' && valid_pct_enc_string(t))
+ pct_decode(t);
+ }
+
+ return s;
+}