[prettify] Need to escape single quotes inside strings

RESOLVED DUPLICATE of bug 956567

Status

RESOLVED DUPLICATE of bug 956567
5 years ago
5 months ago

People

(Reporter: PatrickWesterhoff, Unassigned)

Tracking

Trunk

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

5 years ago
I was just looking at some prettyfied source when I noticed that the prettyfier actually introduced a syntax error into it.

The original, minified code had something like this in it:

    debugMessage("there's no active socket: " + …

Now, this is what the prettyfier made from that part:

    debugMessage('there's no active socket: ' + …

For some reason, the prettifier changes double quotation marks into single quotation marks. While doing that, it does not escape already existing single quotation marks that are part of the string. Obviously, this breaks the prettified code.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Quotation marks change when prettifying source → [prettify] Need to escape single quotes inside strings
(Reporter)

Comment 1

5 years ago
In response to the changed title: The alternative would be to keep the existing quotation marks the way they are. So when the minimized source uses double quotation marks, keep them as double quotation marks, instead of trying to force single quotation marks on everything.
(In reply to Patrick Westerhoff from comment #1)
> In response to the changed title: The alternative would be to keep the
> existing quotation marks the way they are. So when the minimized source uses
> double quotation marks, keep them as double quotation marks, instead of
> trying to force single quotation marks on everything.

Unfortunately, acorn's lexer doesn't tell us whether the string used single or double quotes, so we have to just pick one and use it.
(In reply to Nick Fitzgerald [:fitzgen] from comment #2)
> (In reply to Patrick Westerhoff from comment #1)
> > In response to the changed title: The alternative would be to keep the
> > existing quotation marks the way they are. So when the minimized source uses
> > double quotation marks, keep them as double quotation marks, instead of
> > trying to force single quotation marks on everything.
> 
> Unfortunately, acorn's lexer doesn't tell us whether the string used single
> or double quotes, so we have to just pick one and use it.

Then I suggest we use double quotes instead of single quotes. Single quotes are mote frequently used in strings and sentences in any language (as punctuation marks etc.) than double quotes.
IME, single quote is used more often than double quote in JS, but I'll r+ a patch that fixes the escaping issue and switches to double quotes instead of single quotes. Doesn't matter too much to me.

Comment 5

5 years ago
Looks like same as bug 956567.
Indeed, good catch.
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 956567
(Reporter)

Comment 7

5 years ago
Is there a reason why this was closed in favor of the other one when this one contained more comments? Just wondering if there is some common practice for it.
It was older and had STR that showed pretty printing creating invalid JS.

Updated

5 months ago
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.