extract-word: also handle EXTRACT_UNESCAPE_RELAX in the escape branch

extract_first_word() handled a backslash followed by another character in the
escape-processing branch only when EXTRACT_CUNESCAPE or EXTRACT_UNESCAPE_SEPARATORS
was set. With EXTRACT_UNESCAPE_RELAX alone, the backslash was silently dropped and
only the following character kept, which is inconsistent with the documented "keep
invalid escapes verbatim" intent of RELAX. Let RELAX also enter that branch, so an
invalid escape like "\x" is preserved verbatim as "\x" rather than collapsing to
"x".

EXTRACT_UNESCAPE_RELAX is not used on its own anywhere outside the test cases —
the non-test callers always combine it with EXTRACT_CUNESCAPE, which already enters
this branch — so only the test cases that use RELAX by itself are affected, and
their expectations are updated accordingly.
This commit is contained in:
wyu
2026-08-13 10:36:11 +08:00
parent 2bb1f6a651
commit 609f8d0214
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
return -EINVAL;
}
if (flags & (EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS)) {
if (flags & (EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS|EXTRACT_UNESCAPE_RELAX)) {
bool eight_bit = false;
char32_t u;