Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON encoding error in browser extension code #19

Open
actualben opened this issue May 24, 2022 · 0 comments
Open

JSON encoding error in browser extension code #19

actualben opened this issue May 24, 2022 · 0 comments

Comments

@actualben
Copy link

Some Safari extensions have quotation marks in their names, and this causes KnockKnock to generate malformed JSON in its output.

Parallels Desktop for Mac includes one such Safari extension. It is called: "Open In" button for Internet Explorer. In fact you can't remove this extension without uninstalling Parallels Desktop entirely. Here's a snippet of /Applications/Parallels Desktop.app/Contents/PlugIns/com.parallels.desktop.console.OpenInIE.appex/Contents/Info.plist

<key>CFBundleDisplayName</key>
<string>"Open In" button for Internet Explorer</string>
<key>CFBundleExecutable</key>
<string>com.parallels.desktop.console.OpenInIE</string>
<key>CFBundleGetInfoString</key>
<string>17.1.2, Copyright 2022 Parallels International GmbH</string>
<key>CFBundleIdentifier</key>
<string>com.parallels.desktop.console.OpenInIE</string>

When this extension is present, the following malformed JSON snippet is emitted by KnockKnock:

{"name": ""Open In" button for Internet Explorer", "path": "/Applications/Parallels Desktop.app/Contents/PlugIns/com.parallels.desktop.console.OpenInIE.appex", "identifier": "8AA15FB3-EC66-41B6-9146-EBE12092C87B", "details": "Opens a web page in Internet Explorer inside Windows virtual machine powered by Parallels.", "browser": "/Applications/Safari.app"}

...rather than what you'd expect:

{"name": "\"Open In\" button for Internet Explorer", "path": "/Applications/Parallels Desktop.app/Contents/PlugIns/com.parallels.desktop.console.OpenInIE.appex", "identifier": "8AA15FB3-EC66-41B6-9146-EBE12092C87B", "details": "Opens a web page in Internet Explorer inside Windows virtual machine powered by Parallels.", "browser": "/Applications/Safari.app"}

With the malformed json the internal prettifier fails to parse its input, which may be what is happening in issue #12.

I believe the problem is here, where these value arguments are interpolated into the string unescaped:

json = [NSString stringWithFormat:@"\"name\": \"%@\", \"path\": \"%@\", \"identifier\": \"%@\", \"details\": \"%@\", \"browser\": \"%@\"", self.name, self.path, self.identifier, escapedDetails, self.browser];

Would you be interested in a PR that implements the NSCoding protocol on these classes? That would simplify the code and avoid the finicky manual JSON construction. Implementing NSCoding would basically make it possible to save and open past scans (or other people's scans) via NSKeyedArchiver... which might be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant