Thu, 07 Sep 2023 10:51:13 +0200
fix send_string_escaped
/* * 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; }