-
Notifications
You must be signed in to change notification settings - Fork 27
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
Single quotes in JSON string cause error #37
Comments
Thanks for raising this! It seems like it should be a fairly simple fix just escaping single quotes in the message before concatenating the strings. I was hoping there would be a good way to reproduce this with tests, but the testing situation here is still not quite what I'd like it to be 😞 |
I found a suspicious workaround in our code that looks like backslashes should probably be escaped as well. They do not cause errors like single quotes do, but we currently have to escape newlines and tabs in our message handler code because they prevent the message from being parsed as JSON: const jsonString = message.replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t');
const json = JSON.parse(jsonString); |
I wonder if a simple solution is to use backtick strings instead of single-quote strings... there's a small chance that breaks on really old webviews, but I'm not sure Cordova still works on anything that old. But maybe that doesn't fix the newlines and other special characters? |
Closes AyogoHealth#20. Closes AyogoHealth#31. Closes AyogoHealth#33. Closes AyogoHealth#37. Co-Authored-By: Darrell Wu <[email protected]> Co-Authored-By: Stefan Erkenberg <[email protected]> Co-Authored-By: Michael Manzinger <[email protected]>
Hi there,
If the JSON from the OAuth provider contains single quotes, it causes an error.
Example (with misconfigured Azure AD):
In the Chrome/Safari dev tools it just shows up as something like
Uncaught SyntaxError: Unexpected identifier VM296:1
The cause seems to be that the JSON string is just pasted into the generated JavaScript code without escaping single quotes, which would result in invalid code like this:
It affects both Android and iOS:
cordova-plugin-oauth/src/android/OAuthPlugin.java
Line 126 in 2aa2aad
cordova-plugin-oauth/src/ios/OAuthPlugin.swift
Line 208 in 2aa2aad
Thanks for looking into it!
The text was updated successfully, but these errors were encountered: