-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the restricted file names sanitization
- Loading branch information
Showing
3 changed files
with
77 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,44 @@ | ||
#include "io/bb/sanitizedstring.h" | ||
#include <QString> | ||
#include <QRegularExpression> | ||
#include <gtest/gtest.h> | ||
|
||
namespace pboman3::io::test { | ||
struct CtorParam { | ||
struct SanitizedStringTestParam { | ||
const QString sourceText; | ||
const QString expectedText; | ||
const QString expectedTextOrPattern; | ||
}; | ||
|
||
class CtorTest : public testing::TestWithParam<CtorParam> { | ||
class SanitizedStringRestrictedCharactersTest : public testing::TestWithParam<SanitizedStringTestParam> { | ||
}; | ||
|
||
TEST_P(CtorTest, Deals_With_Restricted_Characters) { | ||
TEST_P(SanitizedStringRestrictedCharactersTest, Deals_With_Restricted_Characters) { | ||
SanitizedString ss(GetParam().sourceText); | ||
ASSERT_EQ(static_cast<QString>(ss), GetParam().expectedText); | ||
ASSERT_EQ(static_cast<QString>(ss), GetParam().expectedTextOrPattern); | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P(SanitizedStringTest, CtorTest, testing::Values( | ||
CtorParam{"\t1\t", "%91%9"}, | ||
CtorParam{"?1?", "%3f1%3f"}, | ||
CtorParam{"*1*", "%2a1%2a"}, | ||
CtorParam{"1///", "1%2f%2f%2f"}, | ||
CtorParam{"\\2", "%5c2"} | ||
)); | ||
INSTANTIATE_TEST_SUITE_P(TestSuite, SanitizedStringRestrictedCharactersTest, testing::Values( | ||
SanitizedStringTestParam{"\t1\t", "%91%9"}, | ||
SanitizedStringTestParam{"?1?", "%3f1%3f"}, | ||
SanitizedStringTestParam{"*1*", "%2a1%2a"}, | ||
SanitizedStringTestParam{"1///", "1%2f%2f%2f"}, | ||
SanitizedStringTestParam{"\\2", "%5c2"} | ||
)); | ||
|
||
class SanitizedStringRestrictedKeywordsTest : public testing::TestWithParam<SanitizedStringTestParam> { | ||
}; | ||
|
||
TEST_P(SanitizedStringRestrictedKeywordsTest, Deals_With_Restricted_Keywords) { | ||
SanitizedString ss(GetParam().sourceText); | ||
QRegularExpression re(GetParam().expectedTextOrPattern); | ||
const QRegularExpressionMatch match = re.match(static_cast<QString>(ss)); | ||
ASSERT_TRUE(match.hasMatch()); | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P(TestSuite, SanitizedStringRestrictedKeywordsTest, testing::Values( | ||
SanitizedStringTestParam{"COn", "^COn-\\d{1,4}"}, | ||
SanitizedStringTestParam{"COM1", "^COM1-\\d{1,4}"}, | ||
SanitizedStringTestParam{"lPt2", "^lPt2-\\d{1,4}"}, | ||
SanitizedStringTestParam{"NUL", "^NUL-\\d{1,4}"} | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters