Skip to content

Commit

Permalink
Sort params named_matches by len
Browse files Browse the repository at this point in the history
This searches for larger (more specific) matches first so that
for example matchid and match get matched independently.

Added _ to regex to match for params specified as match_id
  • Loading branch information
theraspb3rry committed Mar 24, 2024
1 parent b7f53d1 commit 5cec01c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pyrqlite/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _substitute_params(self, operation, parameters):
param_matches = 0

qmark_re = re.compile(r"(\?)")
named_re = re.compile(r"(:{1}[a-zA-Z]+?\b)")
named_re = re.compile(r"(:{1}[a-zA-Z_]+?\b)")

qmark_matches = qmark_re.findall(operation)
named_matches = named_re.findall(operation)
Expand All @@ -123,7 +123,7 @@ def _substitute_params(self, operation, parameters):
raise ProgrammingError('Unamed binding used, but you supplied '
'a dictionary (which has only names): '
'%s %s' % (operation, parameters))
for op_key in named_matches:
for op_key in sorted(named_matches, key=len, reverse=True):
try:
operation = operation.replace(op_key,
_adapt_from_python(parameters[op_key[1:]]))
Expand Down

0 comments on commit 5cec01c

Please sign in to comment.