Open Bug 1540167 Opened 6 years ago Updated 2 years ago

text/plain or text/html responses having quoted text get parsed by JSON.parse() which disappears on hover

Categories

(DevTools :: Netmonitor, defect, P3)

65 Branch
defect

Tracking

(Not tracked)

People

(Reporter: hemakshis, Unassigned)

References

(Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36

Steps to reproduce:

  1. Open Netmonitor
  2. Visit page https://bugzilla-tests.glitch.me/bugs/quotedtext
  3. Click on both the buttons
  4. Go to Response Panel
  5. Notice both the responses have the "JSON" view with the response text, which disappears on hover

Any text with quotes get parsed by JSON (https://searchfox.org/mozilla-central/source/devtools/client/netmonitor/src/components/ResponsePanel.js#121)

Actual results:

The response text gets displayed beside the JSON view header which disappears on hover.

Expected results:

I don't know if it is expected to be displayed in JSON tree (because it is a valid JSON) but it should definitely not be displayed beside the heading and hover thing is definitely a bug.

I can reproduce this, thanks for the report!

Honza

Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3

Hi @honza,

Can you please tell if it is expected to show such responses in the JSON tree? Because JSON.parse("\"anytext\""); actually evaluates to a correct JSON value.
But what if the user actually intended to pass a text/plain or text/html response?

Flags: needinfo?(odvarko)

(In reply to Hemakshi Sachdev [:hemakshis] from comment #2)

Can you please tell if it is expected to show such responses in the JSON tree? Because JSON.parse("\"anytext\""); actually evaluates to a correct JSON value.

I think that we should display the text inside the section - not next to (and within) the section title

But what if the user actually intended to pass a text/plain or text/html response?

Good point. I think that if the response is plain text we could display the JSON section only if the contentType is JSON.

Here is a link to the code base that does such JSON contentType check
https://searchfox.org/mozilla-central/rev/201450283cddc9e409cec707acb65ba6cf6037b1/devtools/client/netmonitor/src/components/ResponsePanel.js#134

Honza

Flags: needinfo?(odvarko)

Hi @Honza,

An update on the issue. JSON correctly parses for the following two types of responses and for them we see the hover defect for them:-

JSON.parse('"Hi"'); OR JSON.parse("\"Hi\"");, returns a string Hi

JSON.parse('true'); OR JSON.parse("true"); returns a boolean true

Now, here we can check that if the json is of type string or boolean and then we will also check if the contentType is plain/text or html/text and if so mark json as null.

What do you think?

Flags: needinfo?(odvarko)

Thanks for the update!

My comments:

  1. I think that we should always display the JSON section if the response is using JSON content type.
  2. JSON data should always be rendered in the content of the JSON section
  3. In other cases, we shouldn't display the JSON section for primitive values (just like you wrote), but we can if the response is actually parsable JSON (it might be useful in cases where the server isn't using the right content type for JSON responses)
  4. We should also check the Params tab - it should behave the same, but it should be probably a follow up.

Does that make sense?

Honza

Flags: needinfo?(odvarko)
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.