3
* Copyright (c) 2018 Kristaps Dzonsons <kristaps@bsd.lv>
5
* Permission to use, copy, modify, and distribute this software for any
6
* purpose with or without fee is hereby granted, provided that the above
7
* copyright notice and this permission notice appear in all copies.
9
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37
static const struct test tests[] = {
39
{ "foobar", "foobar" },
40
{ "foo bar", "foo+bar" },
41
{ "foo~bar", "foo~bar" },
42
{ "foo-bar", "foo-bar" },
43
{ "foo_bar", "foo_bar" },
44
{ "foo.bar", "foo.bar" },
45
{ "foo.bar.", "foo.bar." },
46
{ "foo.bar.-", "foo.bar.-" },
47
{ "-_foo.bar.-", "-_foo.bar.-" },
48
{ "-_foo+bar.-", "-_foo%2Bbar.-" },
49
{ "-_foo\tbar.-", "-_foo%09bar.-" },
50
{ "\t-_foo\tbar.-", "%09-_foo%09bar.-" },
51
{ "\t-_foo\tbar.-\t", "%09-_foo%09bar.-%09" },
52
{ "\t-_foo%\tbar.-\t", "%09-_foo%25%09bar.-%09" },
53
{ "-_foo%09}bar.-", "-_foo%2509%7Dbar.-" },
54
{ "\t\t\t\t", "%09%09%09%09" },
59
main(int argc, char *argv[])
64
if (kutil_urlencode(NULL) != NULL)
65
errx(EXIT_FAILURE, "kutil_urlencode should fail");
67
for (t = tests; t->input != NULL; t++) {
68
if ((url = kutil_urlencode(t->input)) == NULL)
69
err(EXIT_FAILURE, "kutil_urlencode");
70
if (strcmp(url, t->output))
71
errx(EXIT_FAILURE, "%s: fail (have %s, "
72
"want %s)", t->input, url, t->output);