fix(extensions): tolerate non-string catalog name in display-name lookup#3747
Open
Noor-ul-ain001 wants to merge 1 commit into
Open
fix(extensions): tolerate non-string catalog name in display-name lookup#3747Noor-ul-ain001 wants to merge 1 commit into
Noor-ul-ain001 wants to merge 1 commit into
Conversation
_resolve_catalog_extension() filters catalog search results by display
name with `ext["name"].lower() == argument.lower()`. Extension catalog
JSON is user-editable, so a hand-authored non-string name (e.g.
`name: 123`) crashes the filter with `AttributeError: 'int' object has
no attribute 'lower'`, taking down `extension info <name>` and
`extension add <name>`. A missing `name` key would likewise KeyError.
Coerce defensively with `str(ext.get("name", "")).lower()`, matching the
ambiguous-match display block just below (which already str()-coerces
name for the same reason). A bad-named entry simply doesn't match,
yielding a clean not-found error instead of a traceback.
Adds a regression test invoking `extension info <name>` against a
mocked catalog whose search result has `name: 123`; it fails pre-fix
with AttributeError.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@
Summary
_resolve_catalog_extension()(used byextension info <name>andextension add <name>) resolves an argument to a catalog entry by display name:Extension catalog JSON is user-editable, so
catalog.search()can return an entry whosenameis a non-string. A hand-authoredname: 123crashes the filter:which takes down
extension info <name>/extension add <name>with a raw traceback. A missingnamekey would similarly raiseKeyError.Notably, the ambiguous-match display block a few lines below already
str()-coerces the name (_escape_markup(str(ext.get("name", "")))) — so the code already acknowledgesnamemay be non-string/absent; only the filter line missed it.Fix
Coerce defensively with
str(ext.get("name", "")).lower(), matching that sibling block. A bad-named entry simply fails to match, producing a clean not-found error instead of a traceback. Same bug class as the presets fix in #3743.Testing
Adds
test_add_by_name_tolerates_non_string_catalog_name, which invokesextension info <name>against a mocked catalog whose search result hasname: 123. It fails pre-fix withAttributeErrorand passes after; the existing display-name resolution test stays green.🤖 Generated with Claude Code
@