question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not Escape HTML in JSON

See original GitHub issue

Describe the bug My local http server replies to the endpoint below with {"data":{"test":"it's a && b || c + 1!?"},"status":"success"} and the HTTP header Content-Type" is set to "application/json;charset=utf-8". However, Unirest doesn’t decode the answer with UTF-8.

To Reproduce Here is my code:

public static void main(String[] args) throws Exception{
        Unirest.config().verifySsl(false);
        HttpResponse<JsonNode> jsonNode = Unirest.get("https://localhost:8443/status").asJson();
        System.out.println(jsonNode.getBody());
    }

Which prints {"data":{"test":"it\u0027s a \u0026\u0026 b || c + 1!?"},"status":"success"}

I am not using HTTP compression or anything else that I could think of that could break this. If I extract a HttpResponse<byte[]> instead and decode it with UTF-8 manually I obtain the expected result.

Expected behavior Decode the answer correctly and get {“data”:{“test”:“it’s a && b || c + 1!?”},“status”:“success”}

Environmental Data:

  • Java Version: 11.0.1

Additional context The artifact I am using is

<dependency>
            <groupId>com.konghq</groupId>
            <artifactId>unirest-java</artifactId>
            <version>3.11.01</version>
</dependency>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
rybercommented, Oct 17, 2020

Complete in 3.11.02

0reactions
pedr0-frcommented, Oct 19, 2020

Could be up to 10 MB of hexadecimal data, which would be highly compressable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What do I need to escape in my HTML (JSON response)
You do need to escape HTML in JS strings in an HTML file. In other words, if you have an HTML file with...
Read more >
4 Things You Must Do When Putting HTML in JSON
Putting HTML in JSON – Four Things You Must Do · Escape quotation marks used around HTML attributes like so <img src=\"someimage.png\" />...
Read more >
apex - Escaping HTML in JSON in rest callout
I switched from hand rolling to creating the JSON by serializing an apex class using System.JSON.Serialize which handles the escaping.
Read more >
http.NewRequest escapes HTML in JSON body : r/golang
When I request a JSON with HTML inside, the HTML special characters are escaped and I don't know why!? It does not occur...
Read more >
Dont escape html string - Learn - Elm Discourse
Try taking a look at this issue on GitHub. It explains why there isn't a function for inserting HTML from a String and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found