mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
regex: fix newline matching with negated brackets
With REG_NEWLINE, POSIX says: "A <newline> in string shall not be matched by a period outside a bracket expression or by any form of a non-matching list"
This commit is contained in:
parent
e6917eced2
commit
9571c5314a
1 changed files with 14 additions and 0 deletions
|
@ -636,6 +636,20 @@ static reg_errcode_t parse_bracket(tre_parse_ctx_t *ctx, const char *s)
|
|||
goto parse_bracket_done;
|
||||
|
||||
if (neg.negate) {
|
||||
/*
|
||||
* With REG_NEWLINE, POSIX requires that newlines are not matched by
|
||||
* any form of a non-matching list.
|
||||
*/
|
||||
if (ctx->cflags & REG_NEWLINE) {
|
||||
lit = tre_new_lit(&ls);
|
||||
if (!lit) {
|
||||
err = REG_ESPACE;
|
||||
goto parse_bracket_done;
|
||||
}
|
||||
lit->code_min = '\n';
|
||||
lit->code_max = '\n';
|
||||
lit->position = -1;
|
||||
}
|
||||
/* Sort the array if we need to negate it. */
|
||||
qsort(ls.a, ls.len, sizeof *ls.a, tre_compare_lit);
|
||||
/* extra lit for the last negated range */
|
||||
|
|
Loading…
Add table
Reference in a new issue