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

Improve json detection for formatted text #1309

Merged
merged 1 commit into from
Apr 12, 2024
Merged

Improve json detection for formatted text #1309

merged 1 commit into from
Apr 12, 2024

Conversation

Pablete1234
Copy link
Member

Currently we only parse xml strings as json if the strictly start with {" and end with "}, this works fine for strings like: {"text": "a", "color": "red"} but fails very quickly when you try to do anything slightly more complex like {text:"a",clickEvent:{...}}, since neither the start nor the end will have a " following the }. Furthermore we can't really relax the constraint for the " since we may have strings like {teamA} - {teamB} using replacements to fill in variables.

This pr instead uses a regex to see if it's looking a bit more json-like, checking for it strictly:

  • Starting with [ or {, with potentially many of them and spaces in the middle
  • Followed by "property" or 'property' or simply property (with matching start/end quotes)
  • Followed by :
  • Ending in one or many of ] or }

I think the logic for trying to match for a first property-looking text with a : separator should be enough to catch all valid jsons and avoid matching non-json strings, which need to have diff treatment

@Pablete1234 Pablete1234 added the bug Something isn't working label Mar 16, 2024
@Pablete1234 Pablete1234 added the ready PR is ready to merge label Mar 16, 2024
@Electroid Electroid merged commit aa50c40 into dev Apr 12, 2024
2 checks passed
@Electroid Electroid deleted the improve-json-text branch April 12, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready PR is ready to merge
Development

Successfully merging this pull request may close these issues.

3 participants