Skip to content

Commit bf5a99a

Browse files
committed
Fix Chrome JSON parser to handle root nodes and fix tracking param test
1 parent cefbe98 commit bf5a99a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

bookmark_checker/core/parsers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def parse_node(node: dict[str, Any], folder_path: str = "") -> None:
197197
# Chrome timestamp is microseconds since 1601-01-01
198198
# Convert to Unix timestamp
199199
chrome_epoch = 11644473600000000 # microseconds
200-
unix_timestamp = (int(date_added) - chrome_epoch) / 1000000
200+
unix_timestamp = (int(str(date_added)) - chrome_epoch) / 1000000
201201
added = datetime.fromtimestamp(unix_timestamp)
202202
except (ValueError, OSError):
203203
pass
@@ -211,10 +211,13 @@ def parse_node(node: dict[str, Any], folder_path: str = "") -> None:
211211
source_file=path,
212212
)
213213
collection.add(bookmark)
214-
elif node_type == "folder":
215-
# Folder
214+
elif node_type == "folder" or (not node_type and "children" in node):
215+
# Folder (or root node without explicit type)
216216
name = node.get("name", "").strip()
217-
new_path = f"{folder_path}/{name}" if folder_path else name
217+
if name:
218+
new_path = f"{folder_path}/{name}" if folder_path else name
219+
else:
220+
new_path = folder_path
218221

219222
# Process children
220223
children = node.get("children", [])

tests/test_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,15 @@ def test_all_tracking_params(self) -> None:
7979
for param in params:
8080
url = f"https://example.com/page?{param}=value&keep=me"
8181
result = canonicalize_url(url)
82-
assert param not in result.lower()
83-
assert "keep=me" in result
82+
# Check that param is not in the query string (not just anywhere in URL)
83+
# Parse the result to check query parameters
84+
from urllib.parse import urlparse, parse_qs
85+
86+
parsed = urlparse(result)
87+
query_params = parse_qs(parsed.query)
88+
# Check that the tracking param is not in the query string
89+
assert param.lower() not in [k.lower() for k in query_params.keys()]
90+
assert "keep" in query_params
8491

8592

8693
class TestNormalizeWhitespace:

0 commit comments

Comments
 (0)