Skip to content

Commit f1fc31f

Browse files
Improve reliability of WebKit communication bridge (#437)
Resolves rdar://103089222
1 parent ec1709c commit f1fc31f

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

Sources/SwiftDocC/Infrastructure/Communication/WebKitCommunicationBridge.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ public struct WebKitCommunicationBridge: CommunicationBridge {
4949
do {
5050
let encodedMessage = try JSONEncoder().encode(message)
5151
let messageJSON = String(data: encodedMessage, encoding: .utf8)!
52-
// Escape backticks to avoid conflicting with JavaScript's template string syntax.
53-
.replacingOccurrences(of: "`", with: "\\`")
5452

55-
evaluateJavaScript("window.bridge.receive(JSON.parse(`\(messageJSON)`))") { _, _ in }
53+
evaluateJavaScript("window.bridge.receive(\(messageJSON))") { _, _ in }
5654
} catch let error {
5755
throw CommunicationBridgeError.unableToEncodeMessage(message, underlyingError: error)
5856
}

Tests/SwiftDocCTests/Infrastructure/Communication/WebKitCommunicationBridgeTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class WebKitCommunicationBridgeTests: XCTestCase {
4949
let messageJSON = String(data: encodedMessage, encoding: .utf8)!
5050

5151
let evaluateJavaScript: (String, ((Any?, Error?) -> ())?) -> () = { string, _ in
52-
XCTAssertEqual(string, "window.bridge.receive(JSON.parse(`\(messageJSON)`))")
52+
XCTAssertEqual(string, "window.bridge.receive(\(messageJSON))")
5353
}
5454

5555
let bridge = WebKitCommunicationBridge()

0 commit comments

Comments
 (0)