summaryrefslogtreecommitdiff
path: root/test/WhiteBoxTests.cpp
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2020-06-18 11:07:54 +0200
committerAndras Timar <andras.timar@collabora.com>2020-06-19 11:48:44 +0200
commit2c246eed85e065f07b756ec065d12b47cdac5f17 (patch)
tree75d59f3db5d9b4e51a90da4b4f1f88808cec10ab /test/WhiteBoxTests.cpp
parent8bff7cca1a84d6026acc2e75c28f2dca651ffbea (diff)
Sanitize the access_header.
The access_header can contain a lot of nonsense, like whitespace around or additional \n's or \r's. We used to sanitize that, but then regressed in e95413d151c3f0d9476063c8520dd477342ed235 where the "tokenize by any of \n\r" was by mistake replaced with "tokenize by string '\n\r'". Unfortunately the unit test didn't uncover that, and the further refactorings of the related code have hidden that even more. Change-Id: Ie2bf950d0426292770b599e40ee2401101162ff2 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96638 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'test/WhiteBoxTests.cpp')
-rw-r--r--test/WhiteBoxTests.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp
index bb2f57e4c..a2e676198 100644
--- a/test/WhiteBoxTests.cpp
+++ b/test/WhiteBoxTests.cpp
@@ -33,6 +33,7 @@ class WhiteBoxTests : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testSplitting);
CPPUNIT_TEST(testMessageAbbreviation);
CPPUNIT_TEST(testTokenizer);
+ CPPUNIT_TEST(testTokenizerTokenizeAnyOf);
CPPUNIT_TEST(testReplace);
CPPUNIT_TEST(testRegexListMatcher);
CPPUNIT_TEST(testRegexListMatcher_Init);
@@ -54,6 +55,7 @@ class WhiteBoxTests : public CPPUNIT_NS::TestFixture
void testSplitting();
void testMessageAbbreviation();
void testTokenizer();
+ void testTokenizerTokenizeAnyOf();
void testReplace();
void testRegexListMatcher();
void testRegexListMatcher_Init();
@@ -426,6 +428,67 @@ void WhiteBoxTests::testTokenizer()
LOK_ASSERT_EQUAL(static_cast<size_t>(0), ints.size());
}
+void WhiteBoxTests::testTokenizerTokenizeAnyOf()
+{
+ StringVector tokens;
+ const char delimiters[] = "\n\r"; // any of these delimits; and we trim whitespace
+
+ tokens = Util::tokenizeAnyOf("", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(0), tokens.size());
+
+ tokens = Util::tokenizeAnyOf(" ", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(0), tokens.size());
+
+ tokens = Util::tokenizeAnyOf("A", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(1), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A"), tokens[0]);
+
+ tokens = Util::tokenizeAnyOf(" A", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(1), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A"), tokens[0]);
+
+ tokens = Util::tokenizeAnyOf("A ", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(1), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A"), tokens[0]);
+
+ tokens = Util::tokenizeAnyOf(" A ", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(1), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A"), tokens[0]);
+
+ tokens = Util::tokenizeAnyOf(" A Z ", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(1), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A Z"), tokens[0]);
+
+ tokens = Util::tokenizeAnyOf("\n", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(0), tokens.size());
+
+ tokens = Util::tokenizeAnyOf("\n\r\r\n", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(0), tokens.size());
+
+ tokens = Util::tokenizeAnyOf(" A \nZ ", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(2), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A"), tokens[0]);
+ LOK_ASSERT_EQUAL(std::string("Z"), tokens[1]);
+
+ tokens = Util::tokenizeAnyOf(" A Z\n ", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(1), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A Z"), tokens[0]);
+
+ tokens = Util::tokenizeAnyOf(" A Z \n\r\r\n ", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(1), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A Z"), tokens[0]);
+
+ tokens = Util::tokenizeAnyOf(" A \n\r\r\n \r \n Z \n ", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(2), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A"), tokens[0]);
+ LOK_ASSERT_EQUAL(std::string("Z"), tokens[1]);
+
+ tokens = Util::tokenizeAnyOf(" \r A \n \r \n Z \n ", delimiters);
+ LOK_ASSERT_EQUAL(static_cast<size_t>(2), tokens.size());
+ LOK_ASSERT_EQUAL(std::string("A"), tokens[0]);
+ LOK_ASSERT_EQUAL(std::string("Z"), tokens[1]);
+}
+
void WhiteBoxTests::testReplace()
{
LOK_ASSERT_EQUAL(std::string("zesz one zwo flee"), Util::replace("test one two flee", "t", "z"));