Improved regular expression error message for backrefs

Поиск
Список
Период
Сортировка
От Mark Dilger
Тема Improved regular expression error message for backrefs
Дата
Msg-id E77ABEF5-8CB5-4777-A654-1B1FA32D620E@enterprisedb.com
обсуждение исходный текст
Ответы Re: Improved regular expression error message for backrefs  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hackers,

Please find attached an improvement to the error messages given for invalid backreference usage:

 select 'xyz' ~ '(.)(.)\3';
 ERROR:  invalid regular expression: invalid backreference number
 select 'xyz' ~ '(.)(.)(?=\2)';
-ERROR:  invalid regular expression: invalid backreference number
+ERROR:  invalid regular expression: backreference in lookaround assertion

The first regexp is invalid because only two capture groups exist, so \3 doesn't refer to anything.  The second regexp
isrejected because the regular expression system does not support backreferences within lookaround assertions.  (See
thedocs, section 9.7.3.6. Limits And Compatibility.)  It is flat wrong to say the backreference number is invalid.
Thereis a perfectly valid capture that \2 refers to.  

The patch defines a new error code REG_ENOBREF in regex/regex.h right next to REG_ESUBREG from which it is split out,
ratherthan at the end of the list.  Is there a project preference to add it at the end?  Certainly, that would give a
shortergit diff. 

Are there dependencies on the current error messages which prevent such changes?


—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company




Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Noah Misch
Дата:
Сообщение: Re: replay of CREATE TABLESPACE eats data at wal_level=minimal
Следующее
От: Masahiko Sawada
Дата:
Сообщение: Re: Showing I/O timings spent reading/writing temp buffers in EXPLAIN