Skip to content

Commit

Permalink
Correctly escape CSS before injecting into the pane
Browse files Browse the repository at this point in the history
Example CSS that broke injection before, but not
now (from Apple Dictionaries CSS):

```css
span.hsb:before
{
    /* '•' */
    content: '\2022';
    font-size: 80%;
    vertical-align: 3%;
}
```
  • Loading branch information
mr-pennyworth committed Aug 4, 2024
1 parent 6934cc6 commit 26e193a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions AlfredExtraPane.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.2.5;
MARKETING_VERSION = 0.2.6;
ONLY_ACTIVE_ARCH = NO;
OTHER_CODE_SIGN_FLAGS = "--deep";
PRODUCT_BUNDLE_IDENTIFIER = mr.pennyworth.AlfredExtraPane;
Expand All @@ -434,7 +434,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.2.5;
MARKETING_VERSION = 0.2.6;
ONLY_ACTIVE_ARCH = NO;
OTHER_CODE_SIGN_FLAGS = "--deep";
PRODUCT_BUNDLE_IDENTIFIER = mr.pennyworth.AlfredExtraPane;
Expand Down
5 changes: 3 additions & 2 deletions AlfredExtraPane/WebViewInjection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ private let cssInjectedMessageName = "cssInjected"
/// The only way is to inject a <style> tag into the document by executing
/// JS in the webview.
private func injecterJS(_ cssString: String) -> String {
"""
let escapedCssString = cssString.replacingOccurrences(of: "\\", with: "\\\\")
return """
var style = document.createElement('style');
style.innerHTML = `\(cssString)`;
style.innerHTML = `\(escapedCssString)`;
document.head.appendChild(style);
window.webkit.messageHandlers.\(cssInjectedMessageName).postMessage('done');
"""
Expand Down

0 comments on commit 26e193a

Please sign in to comment.