-
Notifications
You must be signed in to change notification settings - Fork 445
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
Escape quotes for decodeEscapedUnicodeCharacters #602
Conversation
@Treno1 could you please provide the curl response output without jq? A public endpoint is better. I think a valid serialized JSON string should encode |
curl -XGET "https://pastebin.com/raw/bZJP0r5i" |
src/utils/httpClient.ts
Outdated
@@ -254,7 +254,10 @@ export class HttpClient { | |||
} | |||
|
|||
private decodeEscapedUnicodeCharacters(body: string): string { | |||
return body.replace(/\\u([\d\w]{4})/gi, (_, g) => String.fromCharCode(parseInt(g, 16))); | |||
return body.replace(/\\u([\d\w]{4})/gi, (_, g) => { | |||
var char = String.fromCharCode(parseInt(g, 16)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use const
instead of var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/utils/httpClient.ts
Outdated
return body.replace(/\\u([\d\w]{4})/gi, (_, g) => String.fromCharCode(parseInt(g, 16))); | ||
return body.replace(/\\u([\d\w]{4})/gi, (_, g) => { | ||
var char = String.fromCharCode(parseInt(g, 16)); | ||
return char == '\"' ? "\\\"" : char; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ===
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/utils/httpClient.ts
Outdated
return body.replace(/\\u([\d\w]{4})/gi, (_, g) => String.fromCharCode(parseInt(g, 16))); | ||
return body.replace(/\\u([\d\w]{4})/gi, (_, g) => { | ||
var char = String.fromCharCode(parseInt(g, 16)); | ||
return char == '\"' ? "\\\"" : char; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to escape the double quote in a single quote, we can simply write like this
return char === '"' ? '\\"' : char;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Thanks, some minor suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@Treno1 Meged, thanks |
@Treno1 you can verify this in the latest version 0.24.0 |
Server sends me response as
My expectation was that decodeEscapedUnicodeCharacters will convert it to
But result was
{"text":""text""}
with invalid json format errors.
Curl + jq handles that kind of situation perfectly.
So, small pr to fix that behaviour