feat: chapter runtime refactoring and related updates
- Refactor chapter runtime: replace window coordinator/snapshot with warmup orchestrator - Update EPUB core: parser, reading session, JS bridge, navigator layout - Update reader controller: data source, location resolution, persistence - Update chapter runtime: data cache, loader, runtime store, disk cache, warmup orchestrator - Remove deprecated navigation state machine and pagination state - Update text rendering: book cache, HTML normalizer - Update UI: text content view, dark image adjuster, text selection controller - Update settings and reader configuration - Add CODE_REVIEW.md and AUDIT_FINAL.md documentation - Update pod dependencies (remove SSAlertSwift, SnapKit) - Update podspec and pod configuration files Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -166,10 +166,23 @@ enum RDEPUBJavaScriptBridge {
|
||||
return string
|
||||
}
|
||||
|
||||
/// Encodes a string value as a safe JavaScript string literal.
|
||||
///
|
||||
/// Uses JSON serialization to handle escaping of quotes, backslashes, control
|
||||
/// characters, and Unicode, then strips the array wrapper to produce a standalone
|
||||
/// JS string literal (including surrounding quotes).
|
||||
///
|
||||
/// - Parameter value: The string to encode, or `nil` which produces the JS keyword `null`.
|
||||
/// - Returns: A JavaScript string literal safe for inline embedding in JS source.
|
||||
private static func javaScriptStringLiteral(_ value: String?) -> String {
|
||||
guard let value else { return "null" }
|
||||
return jsonString(from: [value], fallback: "[null]")
|
||||
.replacingOccurrences(of: "[", with: "")
|
||||
.replacingOccurrences(of: "]", with: "")
|
||||
guard JSONSerialization.isValidJSONObject([value]),
|
||||
let data = try? JSONSerialization.data(withJSONObject: [value], options: []),
|
||||
let arrayString = String(data: data, encoding: .utf8) else {
|
||||
return "null"
|
||||
}
|
||||
// JSON encodes ["value"] as `["value"]`. Drop the leading `[` and trailing `]`
|
||||
// to yield `"value"` — a valid JS string literal with all special characters escaped.
|
||||
return String(arrayString.dropFirst().dropLast())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user