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 JSON types for fields with uncommon json_name #1004

Merged
merged 4 commits into from
Nov 1, 2024

Conversation

nicole0707
Copy link
Contributor

@nicole0707 nicole0707 commented Oct 31, 2024

Context

This PR enhances the existing logic for handling JSON property names by addressing edge cases to ensure compatibility with JavaScript naming conventions. The update focuses on identifying and properly handling property names that do not conform to valid JavaScript identifiers, such as names starting with digits, containing special characters, or including non-ASCII characters.

Changes

  • Enhanced Edge Case Handling

    • Updated logic to wrap JSON property names in quotes when they:
      • Start with a digit.
      • Contain special characters not allowed in JavaScript identifiers.
      • Include non-ASCII characters.
  • Additional Test Cases

    • Added test cases to verify that the updated logic correctly handles:
      • Property names with special characters (e.g., foo@, foo-bar).
      • Property names starting with digits (e.g., 123foo).
      • Non-ASCII characters in property names (e.g., 你好).
      • Property names containing spaces or escape sequences (e.g., foo bar, foo\nbar).

@CLAassistant
Copy link

CLAassistant commented Oct 31, 2024

CLA assistant check
All committers have signed the CLA.

@nicole0707 nicole0707 marked this pull request as ready for review November 1, 2024 05:53
@timostamm timostamm changed the title feat: add more checks on jsonName Fix JSON types for fields with uncommon json_name Nov 1, 2024
Also remove the unnecessary switch statement. This was probably left in accidentally from initial development.

And run prettier.
Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

Comment on lines 485 to 486
|| containsSpecialChar.test(jsonName)
|| isAscii.test(jsonName)) {
Copy link
Member

Choose a reason for hiding this comment

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

Because the first regex ensures a subset of ASCII, we don't need the ASCII check. Removed it in f095a7d

@timostamm timostamm merged commit a2966f2 into bufbuild:main Nov 1, 2024
21 checks passed
@timostamm timostamm mentioned this pull request Nov 1, 2024
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.

3 participants