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

Prevent escaping slash of URL #127

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Document/CRDT/CRDTText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func stringifyAttributes(_ attributes: TextAttributes) -> [String: String] {
}

return jsonObject.mapValues {
if let result = try? JSONSerialization.data(withJSONObject: $0, options: .fragmentsAllowed) {
if let result = try? JSONSerialization.data(withJSONObject: $0, options: [.fragmentsAllowed, .withoutEscapingSlashes]) {
return String(data: result, encoding: .utf8) ?? ""
} else {
return ""
Expand Down
4 changes: 2 additions & 2 deletions Sources/Util/Dictionary+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ extension AnyValueTypeDictionary {
{
convertedDictionary[key] = stringValue
} else if let value = value as? [String: Any],
let jsonData = try? JSONSerialization.data(withJSONObject: value),
let jsonData = try? JSONSerialization.data(withJSONObject: value, options: [.fragmentsAllowed, .withoutEscapingSlashes]),
let stringValue = String(data: jsonData, encoding: .utf8)
{
convertedDictionary[key] = stringValue
} else if let value = value as? [[String: Any]],
let jsonData = try? JSONSerialization.data(withJSONObject: value),
let jsonData = try? JSONSerialization.data(withJSONObject: value, options: [.fragmentsAllowed, .withoutEscapingSlashes]),
let stringValue = String(data: jsonData, encoding: .utf8)
{
convertedDictionary[key] = stringValue
Expand Down
8 changes: 4 additions & 4 deletions Tests/Integration/TextIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -653,30 +653,30 @@ final class TextIntegrationConcurrentTests: XCTestCase {
var d1JSON = await d1.toSortedJSON()
var d2JSON = await d2.toSortedJSON()

XCTAssertEqual(d1JSON, "{\"k1\":[{\"val\":\"The \"},{\"attrs\":{\"link\":\"https:\\/\\/www.google.com\\/search?q=jumping+fox\"},\"val\":\"fox jumped\"},{\"val\":\".\"}]}")
XCTAssertEqual(d1JSON, "{\"k1\":[{\"val\":\"The \"},{\"attrs\":{\"link\":\"https://www.google.com/search?q=jumping+fox\"},\"val\":\"fox jumped\"},{\"val\":\".\"}]}")
XCTAssertEqual(d1JSON, d2JSON)

try await d1.update { root, _ in
(root.k1 as? JSONText)?.edit(4, 4, "quick ")
}

d1JSON = await d1.toSortedJSON()
XCTAssertEqual(d1JSON, "{\"k1\":[{\"val\":\"The \"},{\"val\":\"quick \"},{\"attrs\":{\"link\":\"https:\\/\\/www.google.com\\/search?q=jumping+fox\"},\"val\":\"fox jumped\"},{\"val\":\".\"}]}")
XCTAssertEqual(d1JSON, "{\"k1\":[{\"val\":\"The \"},{\"val\":\"quick \"},{\"attrs\":{\"link\":\"https://www.google.com/search?q=jumping+fox\"},\"val\":\"fox jumped\"},{\"val\":\".\"}]}")

try await d2.update { root, _ in
(root.k1 as? JSONText)?.edit(14, 14, " over the dog")
}

d2JSON = await d2.toSortedJSON()
XCTAssertEqual(d2JSON, "{\"k1\":[{\"val\":\"The \"},{\"attrs\":{\"link\":\"https:\\/\\/www.google.com\\/search?q=jumping+fox\"},\"val\":\"fox jumped\"},{\"val\":\" over the dog\"},{\"val\":\".\"}]}")
XCTAssertEqual(d2JSON, "{\"k1\":[{\"val\":\"The \"},{\"attrs\":{\"link\":\"https://www.google.com/search?q=jumping+fox\"},\"val\":\"fox jumped\"},{\"val\":\" over the dog\"},{\"val\":\".\"}]}")

try await c1.sync()
try await c2.sync()
try await c1.sync()

d1JSON = await d1.toSortedJSON()
d2JSON = await d2.toSortedJSON()
XCTAssertEqual(d1JSON, "{\"k1\":[{\"val\":\"The \"},{\"val\":\"quick \"},{\"attrs\":{\"link\":\"https:\\/\\/www.google.com\\/search?q=jumping+fox\"},\"val\":\"fox jumped\"},{\"val\":\" over the dog\"},{\"val\":\".\"}]}")
XCTAssertEqual(d1JSON, "{\"k1\":[{\"val\":\"The \"},{\"val\":\"quick \"},{\"attrs\":{\"link\":\"https://www.google.com/search?q=jumping+fox\"},\"val\":\"fox jumped\"},{\"val\":\" over the dog\"},{\"val\":\".\"}]}")
XCTAssertEqual(d1JSON, d2JSON)
}
}
Expand Down