Closed Bug 1985689 Opened 1 year ago Closed 1 year ago

Unterminated string constant error when pretty printing html source in Debugger

Categories

(DevTools :: Source Editor, defect, P2)

Firefox 142
defect

Tracking

(firefox145 fixed)

RESOLVED FIXED
145 Branch
Tracking Status
firefox145 --- fixed

People

(Reporter: martins.mozeiko, Assigned: bomsy)

References

(Blocks 1 open bug)

Details

Attachments

(2 files, 1 external file, 6 obsolete files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0

Steps to reproduce:

I'm using Firefox v142 on Windows 11.

  1. Go to https://h4x0r.org/ website
  2. Open Web Developer Tools
  3. Select Debugger tab and choose "(index)" document
  4. Press "Pretty print source"

Actual results:

Firefox shows this:

Error loading this URI: Unterminated string constant (7:910)
Stack in the worker:requireAcorn/</pp$4.raise@resource://devtools/client/debugger/dist/pretty-print-worker.js:7206:21
requireAcorn/</pp.readString@resource://devtools/client/debugger/dist/pretty-print-worker.js:9042:55
requireAcorn/</pp.getTokenFromCode@resource://devtools/client/debugger/dist/pretty-print-worker.js:8837:25
requireAcorn/</pp.readToken@resource://devtools/client/debugger/dist/pretty-print-worker.js:8561:23
requireAcorn/</pp.nextToken@resource://devtools/client/debugger/dist/pretty-print-worker.js:8552:23
requireAcorn/</pp.next@resource://devtools/client/debugger/dist/pretty-print-worker.js:8513:16
requireAcorn/</pp.getToken@resource://devtools/client/debugger/dist/pretty-print-worker.js:8517:16
#getTokens@resource://devtools/client/debugger/dist/pretty-print-worker.js:9752:29
getPrettifiedCodeAndSourceMap@resource://devtools/client/debugger/dist/pretty-print-worker.js:9580:43
prettyFast@resource://devtools/client/debugger/dist/pretty-print-worker.js:9366:38
prettyPrintInlineScript@resource://devtools/client/debugger/dist/pretty-print-worker.js:10617:34
requireWorkerUtils/workerHandler/</<@resource://devtools/client/debugger/dist/pretty-print-worker.js:3691:58
requireWorkerUtils/workerHandler/<@resource://devtools/client/debugger/dist/pretty-print-worker.js:3689:19

Expected results:

I expected html pretty printed.

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Component: DOM: Core & HTML → Source Editor
Product: Core → DevTools

Reproducible locally with the same HTML source, will simplify the test case. Thanks for the report.

Flags: needinfo?(jdescottes)
Attached file test_case_1.html —

Fails with

Error loading this URI: Unterminated template (1:15)

Flags: needinfo?(jdescottes)
Attached file test_case_2.html —

Fails with

Error loading this URI: Unterminated string constant (1:14)

I tried updating acorn to the latest, it fixed some intermediary issues, but the two uploaded above still fail. Maybe we should report them upstream?

Bomsy: do you know of similar issues with the pretty print worker?

Flags: needinfo?(hmanilla)
Attached file test_upload_html.html (obsolete) —
Attachment #9512068 - Attachment is obsolete: true
Attached file test_case_3.html (obsolete) —
Attached file test_case_4.html (obsolete) —
Attached file test_case_5.html (obsolete) —
Attached file test_case_6.html (obsolete) —
Attachment #9512184 - Attachment filename: file_1985689.txt → file_1985689.html
Attached file test_case_7.html (obsolete) —
Attachment #9512184 - Attachment mime type: text/html → application/octet-stream
Attachment #9512184 - Attachment mime type: application/octet-stream → text/html
Attachment #9512182 - Attachment is obsolete: true
Attachment #9512183 - Attachment is obsolete: true
Attachment #9512186 - Attachment is obsolete: true
Attachment #9512187 - Attachment is obsolete: true
Attachment #9512184 - Attachment is obsolete: true

(In reply to Julian Descottes [:jdescottes] from comment #5)

I tried updating acorn to the latest, it fixed some intermediary issues, but the two uploaded above still fail. Maybe we should report them upstream?

Bomsy: do you know of similar issues with the pretty print worker?

It looks like there might also be some issues on our end. We might be passing invalid JavaScript to acorn which is causing it to throw.

With the reduced example test cases

  • For test_case_2.html => t>console.log(" is passed to acorn.
  • for test_case_1.html => t>console.log(%` is passed to acorn

Seems like the indexes used to strip the javascript from the html here https://searchfox.org/firefox-main/rev/3c23ce1368431d49bae08e8e211f7f2bf4e4829d/devtools/client/debugger/src/actions/sources/prettyPrint.js#194 might not be correct.

Flags: needinfo?(hmanilla)

Thanks for the investigation! Very interesting, this is probably because the emojis show up as 1-length in JS strings but internally are represented by more bytes and therefore trigger offset issues?

Assignee: nobody → hmanilla
Attachment #9512290 - Attachment description: WIP: Bug 1985689 - [devtools] Pretty printing html which contain charaters represented by more than one code unit → Bug 1985689 - [devtools] Pretty printing html which contains charaters represented by more than one code unit r=#devtools
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Severity: -- → S3
Priority: -- → P2
Blocks: 1989870
Pushed by hmanilla@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/69502be263bb https://hg.mozilla.org/integration/autoland/rev/9dc8c20d238e [devtools] Pretty printing html which contains charaters represented by more than one code unit r=devtools-reviewers,ochameau
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 145 Branch
QA Whiteboard: [qa-triage-done-c146/b145]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: