This commit is contained in:
yhirose 2020-08-07 13:35:48 -04:00
parent d84c2993af
commit b3b29ce8f3
2 changed files with 14 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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"(