-
Notifications
You must be signed in to change notification settings - Fork 77
fix handle non-numeric manifest icon keys in get_extension_icon to prevent ValueError crash #131 #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix handle non-numeric manifest icon keys in get_extension_icon to prevent ValueError crash #131 #132
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4035,8 +4035,13 @@ def _persisted_icon_response() -> Optional[Response]: | |||||||||||||||||||||||||||||||||||
| # Check icons object in manifest | ||||||||||||||||||||||||||||||||||||
| manifest_icons = manifest.get("icons", {}) | ||||||||||||||||||||||||||||||||||||
| if manifest_icons: | ||||||||||||||||||||||||||||||||||||
| # Get the largest icon | ||||||||||||||||||||||||||||||||||||
| largest_size = max(manifest_icons.keys(), key=lambda x: int(x)) | ||||||||||||||||||||||||||||||||||||
| # Get the largest icon - only consider numeric keys (e.g. "128", "64") | ||||||||||||||||||||||||||||||||||||
| # Some extensions use non-numeric keys like "48x48" which would cause ValueError | ||||||||||||||||||||||||||||||||||||
| # isinstance guard handles edge cases where manifest was parsed outside of json.load | ||||||||||||||||||||||||||||||||||||
| numeric_keys = [k for k in manifest_icons.keys() if isinstance(k, str) and k.isdigit()] | ||||||||||||||||||||||||||||||||||||
| if not numeric_keys: | ||||||||||||||||||||||||||||||||||||
| raise ValueError(f"No numeric icon size keys found in manifest: {list(manifest_icons.keys())}") | ||||||||||||||||||||||||||||||||||||
| largest_size = max(numeric_keys, key=lambda x: int(x)) | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4038
to
+4044
|
||||||||||||||||||||||||||||||||||||
| icon_rel_path = manifest_icons[largest_size] | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4040
to
4045
|
||||||||||||||||||||||||||||||||||||
| # isinstance guard handles edge cases where manifest was parsed outside of json.load | |
| numeric_keys = [k for k in manifest_icons.keys() if isinstance(k, str) and k.isdigit()] | |
| if not numeric_keys: | |
| raise ValueError(f"No numeric icon size keys found in manifest: {list(manifest_icons.keys())}") | |
| largest_size = max(numeric_keys, key=lambda x: int(x)) | |
| icon_rel_path = manifest_icons[largest_size] | |
| # Accept int keys as well for edge cases where manifest was parsed outside of json.load | |
| numeric_icon_candidates = [] | |
| for k in manifest_icons.keys(): | |
| if isinstance(k, str) and k.isdigit(): | |
| numeric_icon_candidates.append((int(k), k)) | |
| elif isinstance(k, int) and not isinstance(k, bool): | |
| numeric_icon_candidates.append((k, k)) | |
| if not numeric_icon_candidates: | |
| raise ValueError(f"No numeric icon size keys found in manifest: {list(manifest_icons.keys())}") | |
| _, largest_size_key = max(numeric_icon_candidates, key=lambda item: item[0]) | |
| icon_rel_path = manifest_icons[largest_size_key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR keeps only str keys where k.isdigit(). If a manifest has only non-numeric keys like "48x48", numeric_keys is empty and the code raises ValueError at main.py .