Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c04c6c5

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 a23ab2e commit c04c6c5

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

614614
assert(!ATEOS());
615615
c = *v->now++;
616-
if (!iscalnum(c))
616+
617+
/* if it's not alphanumeric ASCII, treat it as a plain character */
618+
if (!('a' <= c && c <= 'z') &&
619+
!('A' <= c && c <= 'Z') &&
620+
!('0' <= c && c <= '9'))
617621
RETV(PLAIN, c);
618622

619623
NOTE(REG_UNONPOSIX);
@@ -755,8 +759,11 @@ lexescape(struct vars *v)
755759
RETV(PLAIN, c);
756760
break;
757761
default:
758-
assert(iscalpha(c));
759-
FAILW(REG_EESCAPE); /* unknown alphabetic escape */
762+
/*
763+
* Throw an error for unrecognized ASCII alpha escape sequences,
764+
* which reserves them for future use if needed.
765+
*/
766+
FAILW(REG_EESCAPE);
760767
break;
761768
}
762769
assert(NOTREACHED);

0 commit comments

Comments
 (0)