Fix #286: regex special char \b applies to alphanumeric only
This commit is contained in:
parent
73700d32a9
commit
b7651f2a10
16
buku.py
16
buku.py
@ -1156,7 +1156,12 @@ class BukuDb:
|
|||||||
if deep:
|
if deep:
|
||||||
q0 += q1 + 'AND '
|
q0 += q1 + 'AND '
|
||||||
else:
|
else:
|
||||||
token = '\\b' + re.escape(token.rstrip('/')) + '\\b'
|
_pre = _post = ''
|
||||||
|
if str.isalnum(token[0]):
|
||||||
|
_pre = '\\b'
|
||||||
|
if str.isalnum(token[-1]):
|
||||||
|
_post = '\\b'
|
||||||
|
token = _pre + re.escape(token.rstrip('/')) + _post
|
||||||
q0 += q2 + 'AND '
|
q0 += q2 + 'AND '
|
||||||
|
|
||||||
qargs += (token, token, token, token,)
|
qargs += (token, token, token, token,)
|
||||||
@ -1168,8 +1173,14 @@ class BukuDb:
|
|||||||
if deep:
|
if deep:
|
||||||
q0 += case_statement(q1) + ' + '
|
q0 += case_statement(q1) + ' + '
|
||||||
else:
|
else:
|
||||||
token = '\\b' + re.escape(token.rstrip('/')) + '\\b'
|
_pre = _post = ''
|
||||||
|
if str.isalnum(token[0]):
|
||||||
|
_pre = '\\b'
|
||||||
|
if str.isalnum(token[-1]):
|
||||||
|
_post = '\\b'
|
||||||
|
token = _pre + re.escape(token.rstrip('/')) + _post
|
||||||
q0 += case_statement(q2) + ' + '
|
q0 += case_statement(q2) + ' + '
|
||||||
|
|
||||||
qargs += (token, token, token, token,)
|
qargs += (token, token, token, token,)
|
||||||
q0 = q0[:-3] + ' AS score FROM bookmarks WHERE score > 0 ORDER BY score DESC)'
|
q0 = q0[:-3] + ' AS score FROM bookmarks WHERE score > 0 ORDER BY score DESC)'
|
||||||
else:
|
else:
|
||||||
@ -1224,7 +1235,6 @@ class BukuDb:
|
|||||||
query = query.replace('WHERE tags', 'WHERE (tags')
|
query = query.replace('WHERE tags', 'WHERE (tags')
|
||||||
query += ') AND tags NOT REGEXP ? '
|
query += ') AND tags NOT REGEXP ? '
|
||||||
query += 'ORDER BY id ASC'
|
query += 'ORDER BY id ASC'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
query = 'SELECT id, url, metadata, tags, desc FROM (SELECT *, '
|
query = 'SELECT id, url, metadata, tags, desc FROM (SELECT *, '
|
||||||
case_statement = "CASE WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END"
|
case_statement = "CASE WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END"
|
||||||
|
Loading…
Reference in New Issue
Block a user