Skip to content

Commit 5bcb15b

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 e2e34df commit 5bcb15b

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
@@ -750,7 +750,11 @@ lexescape(struct vars *v)
750750

751751
assert(!ATEOS());
752752
c = *v->now++;
753-
if (!iscalnum(c))
753+
754+
/* if it's not alphanumeric ASCII, treat it as a plain character */
755+
if (!('a' <= c && c <= 'z') &&
756+
!('A' <= c && c <= 'Z') &&
757+
!('0' <= c && c <= '9'))
754758
RETV(PLAIN, c);
755759

756760
NOTE(REG_UNONPOSIX);
@@ -892,8 +896,11 @@ lexescape(struct vars *v)
892896
RETV(PLAIN, c);
893897
break;
894898
default:
895-
assert(iscalpha(c));
896-
FAILW(REG_EESCAPE); /* unknown alphabetic escape */
899+
/*
900+
* Throw an error for unrecognized ASCII alpha escape sequences,
901+
* which reserves them for future use if needed.
902+
*/
903+
FAILW(REG_EESCAPE);
897904
break;
898905
}
899906
assert(NOTREACHED);

0 commit comments

Comments
 (0)