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

Fix broken links in JSON responses #620

Merged
merged 2 commits into from
Jun 23, 2020
Merged

Fix broken links in JSON responses #620

merged 2 commits into from
Jun 23, 2020

Conversation

jackbravo
Copy link
Contributor

@jackbravo jackbravo commented Jun 22, 2020

Links inside the a JSON response are not displayed properly because JSON encodes strings.

This fix displays the original url but the underlying link is using the parsed string as the link href property.

This is an example JSON response that has this problem:

{
  "authenticateURL": "https://example.com/auth?reg_code=XLMKJDK\u0026mso_id=ATT",
  "expires": 1592867389703
}

The parsed link should be https://example.com/auth?reg_code=XLMKJDK&mso_id=ATT.

Links inside the a JSON response are not displayed properly because JSON encodes strings.

This fix displays the original url but the underlying link is using the parsed string as the link `href` property.
When changing URLs into links, check contentType before attempting to JSON.parse
@Huachao Huachao merged commit ceab939 into Huachao:master Jun 23, 2020
@Huachao
Copy link
Owner

Huachao commented Jun 23, 2020

@jackbravo Merged thanks

@jackbravo jackbravo deleted the patch-1 branch June 23, 2020 18:56
@Huachao
Copy link
Owner

Huachao commented Aug 30, 2020

@jackbravo you can try the latest version 0.24.2

@tangdw
Copy link

tangdw commented Sep 2, 2020

sorry 我没编辑好,我想写的是一个 img

{
"test": "<img src=\"https://shenzhen.aliyuncs.com/aaa/201903/2019032614/file_aaa.jpg\" title=\"\" alt=\"\"/>"
}

@Huachao @jackbravo

@Huachao
Copy link
Owner

Huachao commented Sep 2, 2020

@tangdw the response body you've provided is not JSON actually

{
test: src="[https://aliyuncs.com/asas/201903/2019032614/file_as.jpg"\](https://aliyuncs.com/asas/201903/2019032614/file_as.jpg%22%5C%60)
}

@jackbravo
Copy link
Contributor Author

Indeed, that is not json, it needs " surrounding both the key and the value.

On the other hand, the new release is working great for me with links on json. Thanks @Huachao !

@Huachao
Copy link
Owner

Huachao commented Sep 3, 2020

@jackbravo @tangdw I got the root cause since @jackbravo will try to JSON parse the links of JSON mime type, here so I think we can simply revert the change and the issue in #676 will be solved. @jackbravo as for your case, I forgot that we already have a setting to handle the escape issue, so you just need to set rest-client.decodeEscapedUnicodeCharacters": true in the previous and future versions when I publish a new version

@jackbravo
Copy link
Contributor Author

😮 ! Didn't know about that option. But should work as well.

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

Successfully merging this pull request may close these issues.

3 participants