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):
|
def __init__(self):
|
||||||
# All allowed unicode characters + escaped special characters
|
# All allowed unicode characters + escaped special characters
|
||||||
special_char = r'[\[\](),;=^-]'
|
special_char = r'[\[\](),;=^]'
|
||||||
unescaped_char = '[[\t\n\r -\ud7ff\ue000-\ufffd\U00010000-\U0010ffff]--%s]' % special_char
|
unescaped_char = f'[[\t\n\r -\ud7ff\ue000-\ufffd\U00010000-\U0010ffff]--{special_char}]'
|
||||||
escaped_char = r'\^' + 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 = r'(?:%s|(?:%s))+' % (unescaped_char, escaped_char)
|
||||||
chars_no_space = chars.replace('0020', '0021')
|
chars_no_space = chars.replace('0020', '0021')
|
||||||
# No leading zeros allowed for integers
|
# No leading zeros allowed for integers
|
||||||
|
@ -86,7 +86,9 @@ class Tests(unittest.TestCase):
|
|||||||
|
|
||||||
# Test parsing of text assertions
|
# 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]', a('aa-b'), ''),
|
||||||
|
('/1:3[aa-^--b]', a('aa---b'), ''),
|
||||||
('/1:3[aa^,b,c1]', a('aa,b', 'c1'), ''),
|
('/1:3[aa^,b,c1]', a('aa,b', 'c1'), ''),
|
||||||
('/1:3[,aa^,b]', a(after='aa,b'), ''),
|
('/1:3[,aa^,b]', a(after='aa,b'), ''),
|
||||||
('/1:3[;s=a]', a(s='a'), ''),
|
('/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
|
from read_book.viewport import scroll_viewport, rem_size
|
||||||
|
|
||||||
# CFI escaping {{{
|
# CFI escaping {{{
|
||||||
escape_pat = /[\[\],^();~@!-]/g
|
escape_pat = /[\[\],^();~@!]/g
|
||||||
unescape_pat = /[\^](.)/g
|
unescape_pat = /[\^](.)/g
|
||||||
|
|
||||||
def escape_for_cfi(raw):
|
def escape_for_cfi(raw):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user