From 38ebf44620c1307c5dcfdbbf394eb9f25973f423 Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Sat, 13 Jan 2018 00:24:00 -0800 Subject: [PATCH] tests for unescaping decimal HTML escapes and '+' in URLs --- tests/Makefile.am | 5 +++- tests/html-escape.c | 8 +++++-- tests/url-unescape.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 tests/url-unescape.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 4636391c..534c495a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -87,6 +87,9 @@ json_escape_LDADD = $(LDADD) url_escape_SOURCES = url-escape.c url_escape_LDADD = $(LDADD) +url_unescape_SOURCES = url-escape.c +url_unescape_LDADD = $(LDADD) + html_escape_SOURCES = html-escape.c html_escape_LDADD = $(LDADD) @@ -115,7 +118,7 @@ valid_hostname_LDADD = $(LDADD) port_parsing_LDADD = $(LDADD) 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 diff --git a/tests/html-escape.c b/tests/html-escape.c index f10d0012..69254210 100644 --- a/tests/html-escape.c +++ b/tests/html-escape.c @@ -35,7 +35,9 @@ static char *strings[] = "try to escape \\escapes", "\tbig pile \b\b of stuff\r\n", "", - "\"hi there\"" + "\"hi there\"", + "Ahoy matey!", + "Ahoy matey!" }; static char *encoded_strings[] = @@ -47,7 +49,9 @@ static char *encoded_strings[] = "try to escape \\escapes", " big pile  of stuff ", "<hi there>", - ""hi there"" + ""hi there"", + "Ahoy matey!", + "Ahoy matey!" }; int main() diff --git a/tests/url-unescape.c b/tests/url-unescape.c new file mode 100644 index 00000000..5d933598 --- /dev/null +++ b/tests/url-unescape.c @@ -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 . + */ + +#include +#include +#include +#include + +#include +#include +#include +#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