tests for unescaping decimal HTML escapes and '+' in URLs

This commit is contained in:
Daniel Lenski
2018-01-13 00:24:00 -08:00
parent 92f4d5076e
commit 38ebf44620
3 changed files with 64 additions and 3 deletions

View File

@@ -87,6 +87,9 @@ json_escape_LDADD = $(LDADD)
url_escape_SOURCES = url-escape.c url_escape_SOURCES = url-escape.c
url_escape_LDADD = $(LDADD) url_escape_LDADD = $(LDADD)
url_unescape_SOURCES = url-escape.c
url_unescape_LDADD = $(LDADD)
html_escape_SOURCES = html-escape.c html_escape_SOURCES = html-escape.c
html_escape_LDADD = $(LDADD) html_escape_LDADD = $(LDADD)
@@ -115,7 +118,7 @@ valid_hostname_LDADD = $(LDADD)
port_parsing_LDADD = $(LDADD) port_parsing_LDADD = $(LDADD)
check_PROGRAMS = str-test str-test2 ipv4-prefix ipv6-prefix kkdcp-parsing json-escape ban-ips \ check_PROGRAMS = str-test str-test2 ipv4-prefix ipv6-prefix kkdcp-parsing json-escape ban-ips \
port-parsing human_addr valid-hostname url-escape html-escape cstp-recv \ port-parsing human_addr valid-hostname url-escape url-unescape html-escape cstp-recv \
proxyproto-v1 proxyproto-v1

View File

@@ -35,7 +35,9 @@ static char *strings[] =
"try to escape \\escapes", "try to escape \\escapes",
"\tbig pile \b\b of stuff\r\n", "\tbig pile \b\b of stuff\r\n",
"<hi there>", "<hi there>",
"\"hi there\"" "\"hi there\"",
"Ahoy matey!",
"Ahoy matey&#33"
}; };
static char *encoded_strings[] = static char *encoded_strings[] =
@@ -47,7 +49,9 @@ static char *encoded_strings[] =
"try to escape \\escapes", "try to escape \\escapes",
"&#x0009;big pile &#x0008;&#x0008; of stuff&#x000d;&#x000a;", "&#x0009;big pile &#x0008;&#x0008; of stuff&#x000d;&#x000a;",
"&lt;hi&nbsp;there&gt;", "&lt;hi&nbsp;there&gt;",
"&quot;hi there&quot;" "&quot;hi there&quot;",
"&#65;hoy&#000032;matey!",
"Ahoy matey&#33"
}; };
int main() int main()

54
tests/url-unescape.c Normal file
View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2016 Nikos Mavrogiannopoulos
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include "../src/html.h"
#include "../src/html.c"
static char *strings[] =
{
"Laguna+Beach",
};
static char *decoded_strings[] =
{
"Laguna Beach",
};
int main()
{
char *dec;
unsigned i;
unsigned len;
for (i=0;i<sizeof(strings)/sizeof(strings[0]);i++) {
dec = unescape_url(NULL, strings[i], strlen(strings[i]), &len);
if (strcmp(dec, decoded_strings[i]) != 0) {
fprintf(stderr, "string %d, fails decoding:\n\tinput: '%s'\n\toutput: '%s'\n", i, decoded_strings[i], dec);
exit(1);
}
talloc_free(dec);
}
return 0;
}