Skip to content

Commit dde926b

Browse files
committed
Avoid character classification in regex escape parsing.
For regex escape sequences, just test directly for the relevant ASCII characters rather than using locale-sensitive character classification. This fixes an assertion failure when a locale considers a non-ASCII character, such as "൧", to be a digit. Reported-by: Richard Guo Discussion: https://postgr.es/m/CAMbWs49Q6UoKGeT8pBkMtJGJd+16CBFZaaWUk9Du+2ERE5g_YA@mail.gmail.com Backpatch-through: 11
1 parent 6d60b71 commit dde926b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/backend/regex/regc_lex.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,11 @@ lexescape(struct vars *v)
616616

617617
assert(!ATEOS());
618618
c = *v->now++;
619-
if (!iscalnum(c))
619+
620+
/* if it's not alphanumeric ASCII, treat it as a plain character */
621+
if (!('a' <= c && c <= 'z') &&
622+
!('A' <= c && c <= 'Z') &&
623+
!('0' <= c && c <= '9'))
620624
RETV(PLAIN, c);
621625

622626
NOTE(REG_UNONPOSIX);
@@ -758,8 +762,11 @@ lexescape(struct vars *v)
758762
RETV(PLAIN, c);
759763
break;
760764
default:
761-
assert(iscalpha(c));
762-
FAILW(REG_EESCAPE); /* unknown alphabetic escape */
765+
/*
766+
* Throw an error for unrecognized ASCII alpha escape sequences,
767+
* which reserves them for future use if needed.
768+
*/
769+
FAILW(REG_EESCAPE);
763770
break;
764771
}
765772
assert(NOTREACHED);

0 commit comments

Comments
 (0)