Fix version catalog data loss and string corruption from comments and quotes - #3042
Merged
Merged
Conversation
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.
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.
These cases were found during a local review of
VersionCatalogStepand reproduced againstdc2a4cb. I could not find an existing issue covering them.An unmatched bracket in a trailing comment can cause entries to disappear. For example:
Previously, formatting this input produced only
[versions], removing both entries. This change preserves both entries and the comment, withalphasorted beforezoo.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
unterminatedEntrylint at their starting line.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 toFormatter.computerethrow the exception. These errors fail formatting by default, so affected catalogs may start failing after an upgrade.Updated
CHANGES.md,plugin-gradle/CHANGES.md, andplugin-maven/CHANGES.mdto 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 inlib/src/main/java/com/diffplug/spotless/toml/TODO.md.Validation
All 36
VersionCatalogStepTesttests pass, including existing resource fixtures, idempotence checks, string/comment regressions, line-numbered lint expectations, and unchanged-input checks throughLintState.of.Also passed:
:lib:spotlessJavaCheck:testlib:spotlessJavaCheck:lib:spotbugsMainEnglish is not my first language, so I used AI to help polish the wording of this PR description.