mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont escape - when generating CFI
Also recognize both escaped and unescaped hyphens when parsing CFI
This commit is contained in:
parent
d0c5241e97
commit
6a5126fe36
@ -17,9 +17,11 @@ class Parser:
|
||||
|
||||
def __init__(self):
|
||||
# All allowed unicode characters + escaped special characters
|
||||
special_char = r'[\[\](),;=^-]'
|
||||
unescaped_char = '[[\t\n\r -\ud7ff\ue000-\ufffd\U00010000-\U0010ffff]--%s]' % special_char
|
||||
escaped_char = r'\^' + special_char
|
||||
special_char = r'[\[\](),;=^]'
|
||||
unescaped_char = f'[[\t\n\r -\ud7ff\ue000-\ufffd\U00010000-\U0010ffff]--{special_char}]'
|
||||
# calibre used to escape hyphens as well, so recognize them even though
|
||||
# not strictly spec compliant
|
||||
escaped_char = r'\^' + special_char[:-1] + '-]'
|
||||
chars = r'(?:%s|(?:%s))+' % (unescaped_char, escaped_char)
|
||||
chars_no_space = chars.replace('0020', '0021')
|
||||
# No leading zeros allowed for integers
|
||||
|
@ -86,7 +86,9 @@ class Tests(unittest.TestCase):
|
||||
|
||||
# Test parsing of text assertions
|
||||
('/1:3[aa^,b]', a('aa,b'), ''),
|
||||
('/1:3[aa-b]', a('aa-b'), ''),
|
||||
('/1:3[aa^-b]', a('aa-b'), ''),
|
||||
('/1:3[aa-^--b]', a('aa---b'), ''),
|
||||
('/1:3[aa^,b,c1]', a('aa,b', 'c1'), ''),
|
||||
('/1:3[,aa^,b]', a(after='aa,b'), ''),
|
||||
('/1:3[;s=a]', a(s='a'), ''),
|
||||
|
@ -24,7 +24,7 @@ from __python__ import hash_literals
|
||||
from read_book.viewport import scroll_viewport, rem_size
|
||||
|
||||
# CFI escaping {{{
|
||||
escape_pat = /[\[\],^();~@!-]/g
|
||||
escape_pat = /[\[\],^();~@!]/g
|
||||
unescape_pat = /[\^](.)/g
|
||||
|
||||
def escape_for_cfi(raw):
|
||||
|
Loading…
x
Reference in New Issue
Block a user