Fix CFI parsing of numbers with trailing zeros

Fixes #2029521 [Epub files with non-functional bookmarks](https://bugs.launchpad.net/calibre/+bug/2029521)
This commit is contained in:
Kovid Goyal 2023-08-16 22:05:23 +05:30
parent db540da647
commit ccb6781005
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 1 deletions

View File

@ -26,7 +26,7 @@ class Parser:
# No leading zeros allowed for integers
integer = r'(?:[1-9][0-9]*)|0'
# No leading zeros, except for numbers in (0, 1) and no trailing zeros for the fractional part
frac = r'\.[0-9]*[1-9]'
frac = r'\.[0-9]{1,}'
number = r'(?:[1-9][0-9]*(?:{0})?)|(?:0{0})|(?:0)'.format(frac)
def c(x):
return regex.compile(x, flags=regex.VERSION1)
@ -239,3 +239,8 @@ def decode_cfi(root, cfi):
else:
return
return ans
if __name__ == '__main__':
import sys
print(cfi_sort_key(sys.argv[-1], only_path=False))

View File

@ -79,6 +79,7 @@ class Tests(unittest.TestCase):
('/1~0.01', o('~', 0.01), ''),
('/1~1.301', o('~', 1.301), ''),
('/1@23:34.1', o('@', (23, 34.1)), ''),
('/1@23:34.10', o('@', (23, 34.1)), ''),
('/1~3@3.1:2.3', o('~', 3.0, '@', (3.1, 2.3)), ''),
('/1:0', o(':', 0), ''),
('/1:3', o(':', 3), ''),