Improved regular expression error message for backrefs - Mailing list pgsql-hackers

From Mark Dilger
Subject Improved regular expression error message for backrefs
Date
Msg-id E77ABEF5-8CB5-4777-A654-1B1FA32D620E@enterprisedb.com
Whole thread Raw
Responses Re: Improved regular expression error message for backrefs  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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




Attachment

pgsql-hackers by date:

Previous
From: Noah Misch
Date:
Subject: Re: replay of CREATE TABLESPACE eats data at wal_level=minimal
Next
From: Masahiko Sawada
Date:
Subject: Re: Showing I/O timings spent reading/writing temp buffers in EXPLAIN