mirror of
https://github.com/pvrzz/Portage.git
synced 2026-11-29 05:22:26 +00:00
fix: support SQLite TEXT values in Firefox LSNG export
This commit is contained in:
@@ -21,6 +21,7 @@ class FirefoxLocalStorageTest(unittest.TestCase):
|
||||
|
||||
def test_utf8_utf16_and_compression(self):
|
||||
self.assertEqual(decode_value('日本語'.encode(), 1, 0), '日本語')
|
||||
self.assertEqual(decode_value('日本語', 1, 0), '日本語')
|
||||
self.assertEqual(decode_value('日本語'.encode('utf-16-be'), 0, 0), '日本語')
|
||||
self.assertEqual(decode_value(b'\x05\x10hello', 1, 1), 'hello')
|
||||
with self.assertRaises(ValueError):
|
||||
|
||||
@@ -79,6 +79,11 @@ def snappy_decode(data: bytes) -> bytes:
|
||||
|
||||
|
||||
def decode_value(value, conversion_type, compression_type) -> str:
|
||||
# Gecko LSNG stores some uncompressed UTF-8 values as SQLite TEXT.
|
||||
if isinstance(value, str):
|
||||
if conversion_type == 1 and compression_type == 0:
|
||||
return value
|
||||
raise ValueError('Unexpected SQLite TEXT value encoding')
|
||||
raw = bytes(value)
|
||||
if compression_type == 1:
|
||||
raw = snappy_decode(raw)
|
||||
@@ -124,7 +129,7 @@ def export_profile(profile: Path):
|
||||
raise ValueError('Non-text localStorage key')
|
||||
items[key] = decode_value(value, conversion, compression)
|
||||
sites.append({'origin': origin, 'items': items})
|
||||
except (sqlite3.Error, ValueError, UnicodeError, OSError) as exc:
|
||||
except (sqlite3.Error, ValueError, TypeError, UnicodeError, OSError) as exc:
|
||||
warnings.append(f'Skipped {db.parent.parent.name}: {exc}')
|
||||
return sites, warnings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user