# HG changeset patch # User Olaf Wintermann # Date 1652518144 -7200 # Node ID 4a7dd7ff92c99dab6d214cd93c3d082566d8913d # Parent 017eda1be105368776c927963c1f6ed629c1229f enable util_uri_escape and util_url_escape and add some tests diff -r 017eda1be105 -r 4a7dd7ff92c9 src/server/test/main.c --- a/src/server/test/main.c Fri May 13 21:24:45 2022 +0200 +++ b/src/server/test/main.c Sat May 14 10:49:04 2022 +0200 @@ -46,6 +46,7 @@ #include "writer.h" #include "xml.h" #include "webdav.h" +#include "uri.h" void register_pg_tests(int argc, char **argv, UcxTestSuite *suite); @@ -69,6 +70,12 @@ UcxTestSuite* suite = ucx_test_suite_new(); + // util tests + ucx_test_register(suite, test_util_uri_escape_alphanum); + ucx_test_register(suite, test_util_uri_escape_space); + ucx_test_register(suite, test_util_uri_escape_latin); + ucx_test_register(suite, test_util_uri_escape_kanji); + // vfs tests ucx_test_register(suite, test_vfs_open); ucx_test_register(suite, test_vfs_mkdir); diff -r 017eda1be105 -r 4a7dd7ff92c9 src/server/test/objs.mk --- a/src/server/test/objs.mk Fri May 13 21:24:45 2022 +0200 +++ b/src/server/test/objs.mk Sat May 14 10:49:04 2022 +0200 @@ -36,6 +36,7 @@ TESTOBJ += vfs.o TESTOBJ += xml.o TESTOBJ += writer.o +TESTOBJ += uri.o TESTOBJS = $(TESTOBJ:%=$(TEST_OBJPRE)%) TESTSOURCE = $(TESTOBJ:%.o=test/%.c) diff -r 017eda1be105 -r 4a7dd7ff92c9 src/server/test/uri.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/test/uri.c Sat May 14 10:49:04 2022 +0200 @@ -0,0 +1,108 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2022 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "uri.h" + +#include "../util/util.h" + + +UCX_TEST(test_util_uri_escape_alphanum) { + char *str1 = "/test/path/abc/"; + char str_enc[512]; + + UCX_TEST_BEGIN; + + char *test = util_uri_escape(str_enc, str1); + UCX_TEST_ASSERT(test, "util_uri_escape returned NULL"); + UCX_TEST_ASSERT(!strcasecmp(test, str1), "test != str1"); + + UCX_TEST_END; +} + +UCX_TEST(test_util_uri_escape_space) { + char *str1 = "/test/space in path/"; + char *str_enc_expected = "/test/space%20in%20path/"; + char str_enc[512]; + + UCX_TEST_BEGIN; + + char *test = util_uri_escape(str_enc, str1); + UCX_TEST_ASSERT(test, "util_uri_escape returned NULL"); + UCX_TEST_ASSERT(!strcasecmp(test, str_enc_expected), "unexpected result"); + + UCX_TEST_END; +} + +UCX_TEST(test_util_uri_escape_latin) { + char *str1 = "/test/path/öäütestß/"; + char *str_enc_expected = "/test/path/%C3%B6%C3%A4%C3%BCtest%C3%9F/"; + + char *str2 = "€"; + char *str2_enc_expected = "%E2%82%AC"; + + char str_enc[512]; + + UCX_TEST_BEGIN; + + // test 1 + char *test = util_uri_escape(str_enc, str1); + UCX_TEST_ASSERT(test, "util_uri_escape returned NULL"); + UCX_TEST_ASSERT(!strcasecmp(test, str_enc_expected), "unexpected result"); + + // test 2 + test = util_uri_escape(str_enc, str2); + UCX_TEST_ASSERT(test, "(2) util_uri_escape returned NULL"); + UCX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected), "(2) unexpected result"); + + UCX_TEST_END; +} + +UCX_TEST(test_util_uri_escape_kanji) { + char *str1 = "漢字"; + char *str1_enc_expected = "%E6%BC%A2%E5%AD%97"; + + char *str2 = "/test/エンコーディング/漢字/"; + char *str2_enc_expected = "/test/%E3%82%A8%E3%83%B3%E3%82%B3%E3%83%BC%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0/%E6%BC%A2%E5%AD%97/"; + + char str_enc[512]; + + UCX_TEST_BEGIN; + + // test 1 + char *test = util_uri_escape(str_enc, str1); + UCX_TEST_ASSERT(test, "util_uri_escape returned NULL"); + UCX_TEST_ASSERT(!strcasecmp(test, str1_enc_expected), "unexpected result"); + + // test 2 + test = util_uri_escape(str_enc, str2); + UCX_TEST_ASSERT(test, "(2) util_uri_escape returned NULL"); + UCX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected), "(2) unexpected result"); + + UCX_TEST_END; +} + diff -r 017eda1be105 -r 4a7dd7ff92c9 src/server/test/uri.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/test/uri.h Sat May 14 10:49:04 2022 +0200 @@ -0,0 +1,51 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2022 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef TEST_URI_H +#define TEST_URI_H + +#include "../public/nsapi.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +UCX_TEST(test_util_uri_escape_alphanum); +UCX_TEST(test_util_uri_escape_space); +UCX_TEST(test_util_uri_escape_latin); +UCX_TEST(test_util_uri_escape_kanji); + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_URI_H */ + diff -r 017eda1be105 -r 4a7dd7ff92c9 src/server/util/uri.cpp --- a/src/server/util/uri.cpp Fri May 13 21:24:45 2022 +0200 +++ b/src/server/util/uri.cpp Sat May 14 10:49:04 2022 +0200 @@ -57,7 +57,7 @@ } return flagDbcsUri; */ - return PR_FALSE; + return PR_TRUE; } #ifdef XP_WIN32 @@ -228,7 +228,6 @@ /* --------------------------- util_uri_escape ---------------------------- */ -/* NSAPI_PUBLIC char *util_uri_escape(char *od, const char *s) { int flagDbcsUri = allow_dbcs_uri(); @@ -267,11 +266,10 @@ *d = '\0'; return od; } -*/ /* --------------------------- util_url_escape ---------------------------- */ -/* + NSAPI_PUBLIC char *util_url_escape(char *od, const char *s) { int flagDbcsUri = allow_dbcs_uri(); @@ -310,7 +308,7 @@ *d = '\0'; return od; } -*/ + /* ------------------------- util_uri_strip_params ------------------------- */