Skip to content

fix: keep policy fields with unbalanced brackets in one field - #592

Open
bardrop wants to merge 1 commit into
apache:masterfrom
bardrop-oss:fix-bracket-in-quoted-field
Open

bardrop wants to merge 1 commit into
apache:masterfrom
bardrop-oss:fix-bracket-in-quoted-field

Conversation

@bardrop

@bardrop bardrop commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

BracketAwareCsvParser joins fields until their ( and ) balance, so keyMatch(/a, /b) stays one field. But it counts brackets after csv-parse has removed the quotes, so a quoted field is joined too. And savePolicy writes such a field without quotes. So a policy with an unbalanced bracket in a field can be saved, but then the file fails to load or loads a different policy:

policy saved line load result
alice, data(, read p, alice, data(, read whole file throws Unmatched brackets in policy line
bob, a), (b p, bob, a), (b loads as bob, a),(b (two fields joined into one)
g, carol, :) g, carol, :) throws

Writing the field in quotes by hand (p, alice, "data(", read) does not help either, because the quotes are gone before the count.

Changes:

  • BasicCsvParser.parseFields returns each field with quoted (from the csv-parse cast context). parse returns the same strings as before.
  • BracketAwareCsvParser does not count brackets in quoted fields. A custom base parser keeps the old behavior.
  • FileAdapter.escapeCsv also quotes a field whose brackets do not balance. Balanced fields like keyMatch(/a, /b) are written as before.

Tests: a round trip test in fileAdapter.test.ts and three lines in helper.test.ts (two quoted bracket fields, plus the keyMatch(/a, /b) join that must keep working). The new tests fail before the change. npx jest: 269 passed; tsc, eslint and prettier are clean.

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