Skip to content

🐛 Preserve enclosing demand in value-transforming middlewares - #606

Merged
MiWeiss merged 3 commits into
mainfrom
fix/value-transform-enclosing
Sep 2, 2026
Merged

MiWeiss merged 3 commits into
mainfrom
fix/value-transform-enclosing

Conversation

@MiWeiss

@MiWeiss MiWeiss commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Same root cause as #605, at two more call sites. Middlewares that rewrite a value's representation lose the no-enclosing demand through the Field.value setter, so references get braced into literals.

>>> lib = bibtexparser.parse_string("@article{a, month = jan}", append_middleware=[LatexEncodingMiddleware()])
>>> bibtexparser.write_string(lib)
'@article{a,\n\tmonth = {jan}\n}\n'

Affects LatexEncodingMiddleware, LatexDecodingMiddleware and the four name middlewares.

Fix: save and restore the enclosing around the assignment. The NameParts branch mutates in place and never hits the setter, so it is left alone. model.py untouched.

Known gap, out of scope: latex encoding still escapes the content of unenclosed values, so intro # outro becomes intro \# outro.

Tests: 31 cases, all fail before. Suite 2607 passed, from 2576.


🤖 Generated with Claude Code

@MiWeiss
MiWeiss force-pushed the fix/value-transform-enclosing branch 3 times, most recently from c0b3db7 to 76a7a79 Compare September 2, 2026 20:00
The `Field.value` / `String.value` setters intentionally reset `enclosing`
to `None`. The latex de-/encoding and the name middlewares reassign the
value in place without changing what the value *is*, and thereby dropped
the `no-enclosing` demand set by `RemoveEnclosingMiddleware` on unresolved
string references (`month = jan`) and concatenations (`pages = intro # outro`).
`AddEnclosingMiddleware` then wrapped those in braces on write, silently
turning a reference into a literal.

Save and restore the enclosing around these in-place value assignments,
and add regression tests for fields, `@string` blocks and roundtrips.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@MiWeiss
MiWeiss force-pushed the fix/value-transform-enclosing branch from 76a7a79 to 0fecfb3 Compare September 2, 2026 20:03
@MiWeiss

MiWeiss commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

lgtm

@MiWeiss
MiWeiss force-pushed the fix/value-transform-enclosing branch from 55cce31 to ed320dd Compare September 2, 2026 20:38
@MiWeiss
MiWeiss merged commit dad0662 into main Sep 2, 2026
16 checks passed
@MiWeiss
MiWeiss deleted the fix/value-transform-enclosing branch September 10, 2026 20:04
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.

1 participant