Skip to content

Fix version catalog data loss and string corruption from comments and quotes - #3042

Merged
nedtwigg merged 4 commits into
diffplug:mainfrom
aoto-tech:fix/toml-comment-data-loss
Sep 8, 2026
Merged

Fix version catalog data loss and string corruption from comments and quotes#3042
nedtwigg merged 4 commits into
diffplug:mainfrom
aoto-tech:fix/toml-comment-data-loss

Conversation

@aoto-tech

@aoto-tech aoto-tech commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

These cases were found during a local review of VersionCatalogStep and reproduced against dc2a4cb. I could not find an existing issue covering them.

An unmatched bracket in a trailing comment can cause entries to disappear. For example:

[versions]
zoo = "1.0" # [planned update
alpha = "2.0"

Previously, formatting this input produced only [versions], removing both entries. This change preserves both entries and the comment, with alpha sorted before zoo.

Closing quotes preceded by escaped backslashes can cause the same entry loss inside arrays and inline tables. For example, foo = [ "a\\", "b" ] also produces an empty [bundles] section.

Separately, array splitting changes [ 'a,b', 'c' ] into [ 'a, b', 'c' ], modifying a string value.

Changes

  • Share quoted-string handling across entry balancing, comment detection, and array/inline-table splitting, preserving string contents and significant multiline boundaries.
  • Prevent single-line strings from crossing raw newlines, including after a backslash.
  • Report unfinished entries with an unterminatedEntry lint at their starting line.
  • Increment the serialized state version to invalidate cached results.

Through LintState.of, unfinished entries produce a line-numbered lint while leaving this step's input unchanged, making incomplete formatting visible without returning a partial catalog. Direct calls to Formatter.compute rethrow the exception. These errors fail formatting by default, so affected catalogs may start failing after an upgrade.

Updated CHANGES.md, plugin-gradle/CHANGES.md, and plugin-maven/CHANGES.md to document the fixes and error-reporting behavior, including the PR link.

Quoted keys containing =, such as "a=b", remain an existing parsing limitation outside this change and are tracked in lib/src/main/java/com/diffplug/spotless/toml/TODO.md.

Validation

All 36 VersionCatalogStepTest tests pass, including existing resource fixtures, idempotence checks, string/comment regressions, line-numbered lint expectations, and unchanged-input checks through LintState.of.

Also passed:

  • :lib:spotlessJavaCheck
  • :testlib:spotlessJavaCheck
  • :lib:spotbugsMain

English is not my first language, so I used AI to help polish the wording of this PR description.

Ignore brackets inside comments and quoted strings when collecting entries. Preserve significant multiline boundaries, keep quoted-key options working, and reject unfinished entries instead of returning partial catalogs.

Add regression coverage for comment delimiters, escaping, multiline values, and incomplete input; bump formatter state to invalidate cached results.
Reuse quoted-string scanning for array and inline-table splitting, and reject
physical newlines in single-line strings without skipping them as escapes.

Report unfinished entries as start-line lints so their input stays unchanged
and incomplete formatting is visible instead of silently appearing successful.
Preserve multiline layout for actual comments and multiline strings, without
mistaking quoted markers for either. Add regression coverage and update known
limitations.
@nedtwigg
nedtwigg merged commit cd8b6e2 into diffplug:main Sep 8, 2026
20 checks passed
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.

2 participants