Code

Opened 3 years ago

Closed 3 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:

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)

15927.patch (883 bytes) - added by aaugustin 3 years ago.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 3 years ago by aaugustin

  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Indeed, the current regex r'(?![^%])%s' is equivalent to r'%s'. The first part r'(?![^%])' will match if and only if it is not followed by r'[^%]', 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.

Changed 3 years ago by aaugustin

comment:2 Changed 3 years ago by aaugustin

  • Resolution set to duplicate
  • Status changed from new to closed

It's actually a duplicate of #15155 and #13648.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.