Skip to content

Commit

Permalink
Enforce valid encoding in format strings, anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
eliaskosunen committed Nov 8, 2023
1 parent 877efb9 commit 0529a8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion include/scn/detail/format_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ namespace scn {
const CharT* end) const
{
// TODO: Do we want to validate Unicode in format strings?
#if 1
// We're dealing with text, we probably do.
// We could do codeunit-to-codeunit matching,
// but that could get messy wrt. whitespace matching.
// It's simpler to not allow nonsense.
#if 0
SCN_UNUSED(begin);
SCN_UNUSED(end);
#else
Expand Down
4 changes: 3 additions & 1 deletion tests/unittests/format_string_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,7 @@ TEST(FormatStringTest, LongFormatString4)

TEST(FormatStringTest, MatchLiteralInvalidEncoding)
{
auto result = scn::scan<>("\xc3\na\xa4", "\xc3\n\a\xa4");
auto result = scn::scan<>("\xc3\na\xa4", scn::runtime("\xc3\na\xa4"));
ASSERT_FALSE(result);
EXPECT_EQ(result.error().code(), scn::scan_error::invalid_format_string);
}

0 comments on commit 0529a8f

Please sign in to comment.