Skip to content

plan renderer: ensure JSON strings are completely JSON#34959

Merged
liamcervante merged 1 commit intomainfrom
liamcervante/34954
Apr 11, 2024
Merged

plan renderer: ensure JSON strings are completely JSON#34959
liamcervante merged 1 commit intomainfrom
liamcervante/34954

Conversation

@liamcervante
Copy link
Copy Markdown
Contributor

Don't merge (or at least backport) this until after the release of 1.8.0 has been completed this week.

In #34702 we modified the JSON parsing of the plan renderer to support large (> 2^64) numbers. In doing so we changed the parsing to use the json.Decoder. The Decoder accepts partial JSON strings, so this means that a string that starts with a valid JSON object and then ends with a non-JSON piece of text is interpreted as valid JSON.

This PR updates the renderer so it checks the decoder has consumed the complete string before trusting that the returned object can be rendered as JSON.

In Martin's comments, he details how the ctyjson package supports this and the large number parsing by default. Unfortunately, we can't use the ctyjson package here as the renderer doesn't handle cty.Value objects instead just relying on the raw JSON objects that are available from the jsonplan package.

Fixes #34954

Target Version

v1.8.1

Proposed CHANGELOG

BUG FIXES

  • plan renderer: Correctly render strings that begin with JSON compatible text but don't end with it.

@liamcervante liamcervante added the 1.8-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Apr 8, 2024
@liamcervante liamcervante requested a review from a team April 8, 2024 09:35
@liamcervante liamcervante merged commit 924958b into main Apr 11, 2024
@liamcervante liamcervante deleted the liamcervante/34954 branch April 11, 2024 15:49
@github-actions
Copy link
Copy Markdown
Contributor

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

@github-actions
Copy link
Copy Markdown
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

1.8-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terraform is "magically" running jsonencode() on strings that are not JSON and then producing strange plan output

2 participants