Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fix #122
  • Loading branch information
yhirose committed Aug 7, 2020
1 parent d84c299 commit b3b29ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions peglib.h
Expand Up @@ -180,11 +180,11 @@ inline size_t codepoint_length(const char *s8, size_t l) {
auto b = static_cast<uint8_t>(s8[0]);
if ((b & 0x80) == 0) {
return 1;
} else if ((b & 0xE0) == 0xC0) {
} else if ((b & 0xE0) == 0xC0 && l >= 2) {
return 2;
} else if ((b & 0xF0) == 0xE0) {
} else if ((b & 0xF0) == 0xE0 && l >= 3) {
return 3;
} else if ((b & 0xF8) == 0xF0) {
} else if ((b & 0xF8) == 0xF0 && l >= 4) {
return 4;
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/test1.cc
Expand Up @@ -45,6 +45,17 @@ TEST_CASE("Start rule with ignore operator test", "[general]")
REQUIRE(ret == false);
}

TEST_CASE("Invalid UTF-8 text test", "[general]")
{
std::string s = "a <- '";
s += static_cast<char>(0xe8); // Make invalid utf8 text...

parser parser(s.c_str());

bool ret = parser;
REQUIRE(ret == false);
}

TEST_CASE("Backslash escape sequence test", "[general]")
{
parser parser(R"(
Expand Down

0 comments on commit b3b29ce

Please sign in to comment.