Skip to content

Handle invert() values as literal keys - #680

Open
draarivpatel-ui wants to merge 1 commit into
fabiocaccamo:mainfrom
draarivpatel-ui:fix/invert-literal-keys
Open

draarivpatel-ui wants to merge 1 commit into
fabiocaccamo:mainfrom
draarivpatel-ui:fix/invert-literal-keys

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Fixes #671

invert() inserted values through keypath-aware setdefault(), so string values like one.two were parsed as paths. That produced nested mappings, lost groups for foo / foo[0], and raised AttributeError for some inputs.

This collects the inverted pairs in a plain dict so values are treated as literal keys. Values that a keypath-aware benedict cannot represent literally (containing the keypath separator or index syntax) now raise a clear ValueError instead of being silently reinterpreted.

  • benedict/core/invert.py
  • Regression tests for literal keys and rejected keypath-like values.

tests/core passes (130 tests); ruff check and format are clean.

invert() used keypath-aware setdefault() to build the result, so values containing keypath syntax such as 'one.two' were parsed as paths: they created nested mappings, overwrote unrelated groups, or raised AttributeError. Collect the inverted pairs in a plain dict, then reject values that cannot be represented as literal keys in a keypath-aware benedict instead of silently corrupting the result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

invert() interprets string values as keypaths and can lose groups

1 participant