Fix pdfjs version parsing for never versions
This commit is contained in:
parent
64fc1a3277
commit
e8123bb68a
@ -197,12 +197,14 @@ def _pdfjs_version():
|
||||
return 'no'
|
||||
else:
|
||||
pdfjs_file = pdfjs_file.decode('utf-8')
|
||||
version_re = re.compile(r"^PDFJS\.version = '([^']+)';$", re.MULTILINE)
|
||||
version_re = re.compile(
|
||||
r"^(PDFJS\.version|var pdfjsVersion) = '([^']+)';$", re.MULTILINE)
|
||||
|
||||
match = version_re.search(pdfjs_file)
|
||||
if not match:
|
||||
pdfjs_version = 'unknown'
|
||||
else:
|
||||
pdfjs_version = match.group(1)
|
||||
pdfjs_version = match.group(2)
|
||||
if file_path is None:
|
||||
file_path = 'bundled'
|
||||
return '{} ({})'.format(pdfjs_version, file_path)
|
||||
|
@ -543,25 +543,38 @@ class TestPDFJSVersion:
|
||||
lambda path: (b'foobar', None))
|
||||
assert version._pdfjs_version() == 'unknown (bundled)'
|
||||
|
||||
def test_known(self, monkeypatch):
|
||||
@pytest.mark.parametrize('varname', [
|
||||
'PDFJS.version', # older versions
|
||||
'var pdfjsVersion', # newer versions
|
||||
])
|
||||
def test_known(self, monkeypatch, varname):
|
||||
pdfjs_code = textwrap.dedent("""
|
||||
// Initializing PDFJS global object (if still undefined)
|
||||
if (typeof PDFJS === 'undefined') {
|
||||
(typeof window !== 'undefined' ? window : this).PDFJS = {};
|
||||
}
|
||||
|
||||
PDFJS.version = '1.2.109';
|
||||
VARNAME = '1.2.109';
|
||||
PDFJS.build = '875588d';
|
||||
|
||||
(function pdfjsWrapper() {
|
||||
// Use strict in our context only - users might not want it
|
||||
'use strict';
|
||||
""").strip().encode('utf-8')
|
||||
""".replace('VARNAME', varname)).strip().encode('utf-8')
|
||||
monkeypatch.setattr(
|
||||
'qutebrowser.utils.version.pdfjs.get_pdfjs_res_and_path',
|
||||
lambda path: (pdfjs_code, '/foo/bar/pdf.js'))
|
||||
assert version._pdfjs_version() == '1.2.109 (/foo/bar/pdf.js)'
|
||||
|
||||
def test_real_file(self):
|
||||
"""Test against the real file if pdfjs was found."""
|
||||
try:
|
||||
pdfjs.get_pdfjs_res_and_path('build/pdf.js')
|
||||
except pdfjs.PDFJSNotFound:
|
||||
pytest.skip("No pdfjs found")
|
||||
ver = version._pdfjs_version()
|
||||
assert ver.split()[0] not in ['no', 'unknown'], ver
|
||||
|
||||
|
||||
class FakeQSslSocket:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user