You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
\B matches between the bytes of a UTF-8 character #677
I'd like to investigate #677 and agree on the intended behavior before developing a fix.
I built unmodified RE2 at 2da0056 with C++17 on Linux x86_64. For UTF-8 input aé (bytes 61 c3 a9), an unanchored \B matches at byte offset 2, inside the character. Three- and four-byte UTF-8 examples also select offset 2. NFA, BitState and forward/reverse DFA search agree; an anchored OnePass search accepts the same interior position.
The behavior also affects rewriting:
std::string s = "a\xc3\xa9";
RE2::GlobalReplace(&s, RE2("\\B"), "_");
// Actual bytes: 61 c3 5f a9 5f (invalid UTF-8)
Two compatibility cases matter when choosing a fix: Latin-1 mode legitimately accepts byte offset 2, and \C\B\C currently matches both bytes of UTF-8 é. Input 61 80 80 also accepts offset 2, so rejecting every continuation-byte value would change malformed-input behavior as well.
Should ordinary UTF-8 searches restrict these match positions to code-point boundaries while retaining explicit byte-pattern behavior? What contract should apply to malformed UTF-8 and a caller-supplied start position inside a character? ASCII-only word classification can remain unchanged.
Depending on that contract, the choices appear to be a compiler/empty-width constraint shared by all engines, or a restriction on eligible UTF-8 search starts. The former needs corresponding DFA byte classes/reverse-state handling; the latter needs care to preserve linear-time search and explicit \C behavior. I would add native regression cases for the agreed semantics, all affected engines and Latin-1/byte-pattern controls, then run the full test suite and relevant benchmarks.
Activity
xili-ytl commentedon Oct 27, 2026
Hi RE2 maintainers,
I'd like to investigate #677 and agree on the intended behavior before developing a fix.
I built unmodified RE2 at 2da0056 with C++17 on Linux x86_64. For UTF-8 input
aé(bytes61 c3 a9), an unanchored\Bmatches at byte offset 2, inside the character. Three- and four-byte UTF-8 examples also select offset 2. NFA, BitState and forward/reverse DFA search agree; an anchored OnePass search accepts the same interior position.The behavior also affects rewriting:
Two compatibility cases matter when choosing a fix: Latin-1 mode legitimately accepts byte offset 2, and
\C\B\Ccurrently matches both bytes of UTF-8é. Input61 80 80also accepts offset 2, so rejecting every continuation-byte value would change malformed-input behavior as well.Should ordinary UTF-8 searches restrict these match positions to code-point boundaries while retaining explicit byte-pattern behavior? What contract should apply to malformed UTF-8 and a caller-supplied start position inside a character? ASCII-only word classification can remain unchanged.
Depending on that contract, the choices appear to be a compiler/empty-width constraint shared by all engines, or a restriction on eligible UTF-8 search starts. The former needs corresponding DFA byte classes/reverse-state handling; the latter needs care to preserve linear-time search and explicit
\Cbehavior. I would add native regression cases for the agreed semantics, all affected engines and Latin-1/byte-pattern controls, then run the full test suite and relevant benchmarks.Which direction would you prefer?