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

Escape the string during toJSON. #128

Merged
merged 4 commits into from
Nov 8, 2023
Merged

Escape the string during toJSON. #128

merged 4 commits into from
Nov 8, 2023

Conversation

humdrum
Copy link
Contributor

@humdrum humdrum commented Nov 6, 2023

What this PR does / why we need it:

  • By the JSON spec. special characters must be escaped with a slash. (eg. newline => \n) (https://www.json.org/json-en.html)
  • The toJSON in JSON Node makes JSON string without escaping now. So toJSON string can't be parsed.
    • eg. JSONTreeTextNode(value: "\n").toJSONString
{"type": "text", "value": "
"}
  • I added toJSONString var in String Extension. And explicitly escape the string in toJSONString.
  • I also apply a similar modification to the CRDTTree.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

@humdrum humdrum self-assigned this Nov 6, 2023
Copy link

codecov bot commented Nov 6, 2023

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (4a63cca) 43.02% compared to head (effce02) 43.07%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #128      +/-   ##
==========================================
+ Coverage   43.02%   43.07%   +0.05%     
==========================================
  Files         104      104              
  Lines       22932    22958      +26     
==========================================
+ Hits         9866     9890      +24     
- Misses      13066    13068       +2     
Files Coverage Δ
Tests/Unit/Document/CRDT/CRDTTreeTests.swift 100.00% <100.00%> (ø)
Tests/Unit/Document/JONSTreeTests.swift 100.00% <100.00%> (ø)
Sources/Document/CRDT/CRDTTree.swift 66.93% <66.66%> (ø)
Sources/Util/String+Extensions.swift 57.14% <77.77%> (+7.14%) ⬆️
Sources/Document/Json/JSONTree.swift 21.89% <37.50%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@myupage myupage left a comment

Choose a reason for hiding this comment

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

Works great. Thank you.

Copy link
Member

@hackerwins hackerwins 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 your contribution.

@7hong13 @chacha912 @krapie
This should be applied to other SDKs.

@humdrum humdrum merged commit 7ce2fa0 into main Nov 8, 2023
3 checks passed
@humdrum humdrum deleted the escaped_json_string branch November 8, 2023 01:38
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