Opened 14 years ago
Closed 14 years ago
#15927 closed Bug (duplicate)
FORMAT_QMARK_REGEX in sqlite backend does not work as expected
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3-rc |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
FORMAT_QMARK_REGEX is not correct (in django/db/backends/sqlite3/base.py).
It uses a lookahead assertion trying to not match if the char before the "%s" is not "%" but lookahead assertion can't be used to do that (it is for looking ahead not behind).
Example:
In the regex '(?!..)b' applied on 'abc' the '..' will match 'bc' so: - re.search(r'(?!a)b','abc') => match 'b' - re.search(r'(?!b)b','abc') => no match
I don't think this regex could be writen with lookhead assertions.
A possible solution could be:
re.compile(r'(^|[^%])%s').sub(r'\1?','%s %%s %s')
Attachments (1)
Change History (3)
comment:1 by , 14 years ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 14 years ago
Attachment: | 15927.patch added |
---|
comment:2 by , 14 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Indeed, the current regex
r'(?![^%])%s'
is equivalent tor'%s'
. The first partr'(?![^%])'
will match if and only if it is not followed byr'[^%]'
, which is equivalent to being followed by%
. This is always true since%
is the next character in the regex.This is much clearer with an example; I'm attaching a failing test case.