Skip to content

Conversation

@Vishalup29
Copy link
Contributor

@Vishalup29 Vishalup29 commented Nov 25, 2025

fix(yaml): prevent duplicate tags in sequences

In some YAML sequences, tags were being rendered twice: once in the startBracketPrefix and once attached to the sequence. This caused idempotency issues when formatting YAML.

What's changed?

A minor update to YamlParser to prevent duplicate tags in sequences. The parser now only attaches a tag to a sequence if startBracketPrefix is null, resolving the idempotency issue.

What's your motivation?

Anything in particular you'd like reviewers to focus on?

  • The logic change at the SequenceStartEvent handling in YamlParser:
    if (sse.getTag() != null && startBracketPrefix == null) {
        ...
    }

Reviewers

@greg-at-moderne, @aet2505

fix(yaml): prevent duplicate tags in sequences

In some YAML sequences, tags were being rendered twice: once in the
startBracketPrefix and once attached to the sequence. This caused
idempotency issues when formatting YAML.

Update YamlParser to only attach a tag if startBracketPrefix is null,
resolving the failing test case in openrewrite#5179.
@greg-at-moderne
Copy link
Contributor

Please add a test - e.g. the one mentioned in the issue description.

@greg-at-moderne greg-at-moderne changed the title Fixes #5179 Fixing parsing of YAML tags in sequences Nov 25, 2025
@timtebeek timtebeek added bug Something isn't working parser labels Nov 25, 2025
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Nov 25, 2025
@Vishalup29
Copy link
Contributor Author

Vishalup29 commented Nov 25, 2025

@greg-at-moderne Thanks for taking a look, I see the test was added by @timtebeek
Thanks for the test. Pls review/merge when possible

@greg-at-moderne
Copy link
Contributor

Thanks for coming up with the PR.
I remember the @aet2505 had a comment about this feeling incorrect, but I fail to understand why.

Copy link
Contributor

@greg-at-moderne greg-at-moderne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we merge it. I consider it an improvement. And if new information to light, we might find a better solution.

@timtebeek timtebeek merged commit 4b114c3 into openrewrite:main Nov 26, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Nov 26, 2025
@aet2505
Copy link
Contributor

aet2505 commented Nov 26, 2025

My vague memory is that it felt like a bodge to me because it didn't parse the value as a 'Tag' correctly so potentially would have cases where if you tried to rewrite tags it might not behave as expected.

It definitely felt like it worked for me and I couldn't find the case where it failed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parser yaml

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants