Skip to content

Commit

Permalink
Prevent escaping slash of URL (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
humdrum authored Nov 8, 2023
1 parent 7ce2fa0 commit 9e11024
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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

0 comments on commit 9e11024

Please sign in to comment.