Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow marshaling plain string values into JSON scalars #1743

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

candiduslynx
Copy link
Contributor

Copy link

⏱️ Benchmark results

Comparing with 2460517

  • Glob-8 ns/op: 91.22 ⬇️ 1.30% decrease vs. 2460517

@kodiakhq kodiakhq bot merged commit 87e90b8 into main Jun 19, 2024
9 checks passed
@kodiakhq kodiakhq bot deleted the fix/scalar/json branch June 19, 2024 07:40
kodiakhq bot pushed a commit that referenced this pull request Jun 19, 2024
🤖 I have created a release *beep* *boop*
---


## [4.45.3](v4.45.2...v4.45.3) (2024-06-19)


### Bug Fixes

* Allow marshaling plain string values into JSON scalars ([#1743](#1743)) ([87e90b8](87e90b8))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
@erezrokah
Copy link
Member

Isn't a plain string not a valid JSON? Only a quoted one is a valid JSON?

@candiduslynx
Copy link
Contributor Author

Isn't a plain string not a valid JSON? Only a quoted one is a valid JSON?

yes (as we check a b c) value instead of "a b c"
so when we do json.Marshal it properly escapes the string + quotes it

@@ -15,6 +21,7 @@ func TestJSONSet(t *testing.T) {
{source: "{}", result: JSON{Value: []byte("{}"), Valid: true}},
{source: `"test"`, result: JSON{Value: []byte(`"test"`), Valid: true}},
{source: "1", result: JSON{Value: []byte("1"), Valid: true}},
{source: `json some data`, result: JSON{Value: []byte(`"json some data"`), Valid: true}},
Copy link
Member

Choose a reason for hiding this comment

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

The source value is an unquoted string so not sure why we're treating it as a valid JSON

@erezrokah
Copy link
Member

yes (as we check a b c) value instead of "a b c"
so when we do json.Marshal it properly escapes the string + quotes it

But this PR makes it so that any unquoted string value is treated as a valid JSON no?

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

Successfully merging this pull request may close these issues.

4 participants