Closed Bug 964103 Opened 11 years ago Closed 11 years ago

[prettify] Need to escape single quotes inside strings

Categories

(DevTools :: Debugger, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 956567

People

(Reporter: PatrickWesterhoff, Unassigned)

Details

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
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.
Looks like same as bug 956567.
Indeed, good catch.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
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.
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.