Improve json detection for formatted text #1309
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
[
or{
, with potentially many of them and spaces in the middle"property"
or'property'
or simplyproperty
(with matching start/end quotes):
]
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