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: safe json parse #155

Merged
merged 3 commits into from
Dec 22, 2023
Merged

fix: safe json parse #155

merged 3 commits into from
Dec 22, 2023

Conversation

ganchoradkov
Copy link
Member

@ganchoradkov ganchoradkov commented Dec 8, 2023

  • Updated regex to skip string literals when parsing
  • Added logging on parsing fails

updated regex breakdown

(?<!"): Negative lookbehind assertion ensures that the match is not immediately preceded by a double quote (").

(?<=:): Positive lookbehind assertion ensures that the match is immediately preceded by a colon (:).

\b: Word boundary to ensure that the match is a whole word.

(\d{17,}|(?:[9](...))): Alternation for two possible patterns:

\d{17,}: Matches a sequence of at least 17 digits.
(?: ... ): Non-capturing group for a nested pattern.
[9](...): Matches the digit 9 followed by a nested pattern for specific numeric values.
(?=[,\}\]]|$): Positive lookahead assertion ensures that the match is immediately followed by either ,, }, ], or the end of the string.

@ganchoradkov ganchoradkov linked an issue Dec 8, 2023 that may be closed by this pull request
Copy link
Member

@bkrem bkrem 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 fixing 💪

@ganchoradkov ganchoradkov merged commit fbb3ebf into master Dec 22, 2023
24 checks passed
@ganchoradkov ganchoradkov deleted the fix/safeJsonParse branch December 22, 2023 08:51
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.

SafeJSON.JSONParse mangles number inside of string literal
2 participants