mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-27 18:57:42 +00:00
Properly escapes ' and \ as popup keys.
This commit is contained in:
parent
0213247260
commit
e53bf7fcaf
2 changed files with 16 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ display_usage ( ) {
|
|||
echo " -clean Removes all previously-existing build products for KMEI and the Keyman app before building."
|
||||
echo " -no-kmw Uses existing keyman.js, doesn't try to build"
|
||||
echo " -only-framework Builds only the KeymanEngine framework; does not attempt to build the app."
|
||||
echo " -no-carthage Disables downloading and building for dependencies."
|
||||
echo " -no-codesign Disables code-signing for the Keyman application, allowing it to be performed separately later."
|
||||
echo " Will not construct the archive and .ipa. (includes -no-archive)"
|
||||
echo " -no-archive Bypasses the archive and .ipa preparation stage."
|
||||
|
|
|
|||
|
|
@ -78,7 +78,21 @@ extension KeymanWebViewController {
|
|||
|
||||
// FIXME: text is unused in the JS
|
||||
func executePopupKey(id: String, text: String) {
|
||||
webView.evaluateJavaScript("executePopupKey('\(id)','\(text)');", completionHandler: nil)
|
||||
//var escapedText: String;
|
||||
// Text must be checked for ', ", and \ characters; they must be escaped properly!
|
||||
do {
|
||||
let encodingArray = [ text ];
|
||||
let jsonString = try String(data: JSONSerialization.data(withJSONObject: encodingArray), encoding: .utf8)!
|
||||
let start = jsonString.index(jsonString.startIndex, offsetBy: 2)
|
||||
let end = jsonString.index(jsonString.endIndex, offsetBy: -2)
|
||||
let escapedText = jsonString[start..<end]
|
||||
|
||||
let cmd = "executePopupKey(\"\(id)\",\"\(escapedText)\");"
|
||||
webView.evaluateJavaScript(cmd, completionHandler: nil)
|
||||
} catch {
|
||||
log.error(error)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func setOskWidth(_ width: Int) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue