Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion re2/parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ ParseStatus ParseUnicodeGroup(absl::string_view* s,
absl::string_view name; // Han or L
s->remove_prefix(2); // '\\', 'p'

if (!StringViewToRune(&c, s, status))
if (StringViewToRune(&c, s, status) < 0)
return kParseError;
if (c != '{') {
// Name is the bit of string we just skipped over for c.
Expand Down
15 changes: 15 additions & 0 deletions re2/testing/parse_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,19 @@ TEST(LookAround, ErrorArgs) {
EXPECT_EQ(status.error_arg(), "(?<!");
}

// \p or \P followed by invalid UTF-8 (rather than a group name) must be
// reported as bad UTF-8, matching the \p{...} form.
TEST(UnicodeGroups, BadUTF8) {
RegexpStatus status;
Regexp* re;

re = Regexp::Parse(std::string("\\p\xff"), Regexp::LikePerl, &status);
EXPECT_TRUE(re == NULL);
EXPECT_EQ(status.code(), kRegexpBadUTF8);

re = Regexp::Parse(std::string("\\P\xff"), Regexp::LikePerl, &status);
EXPECT_TRUE(re == NULL);
EXPECT_EQ(status.code(), kRegexpBadUTF8);
}

} // namespace re2