Bug 173053 - \n\r is not the same as \r\n
Summary: \n\r is not the same as \r\n
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords:
Depends on:
Blocks: 170810
  Show dependency treegraph
 
Reported: 2017-06-07 04:34 PDT by Peter van der Zee
Modified: 2017-07-07 12:51 PDT (History)
9 users (show)

See Also:


Attachments
proposed patch. (3.01 KB, patch)
2017-06-07 13:04 PDT, Mark Lam
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews102 for mac-elcapitan (998.07 KB, application/zip)
2017-06-07 14:03 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews106 for mac-elcapitan-wk2 (1.07 MB, application/zip)
2017-06-07 14:10 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews117 for mac-elcapitan (1.74 MB, application/zip)
2017-06-07 14:22 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews121 for ios-simulator-wk2 (6.90 MB, application/zip)
2017-06-07 14:32 PDT, Build Bot
no flags Details
proposed patch w/ updated test baselines. (6.46 KB, patch)
2017-06-10 08:06 PDT, Mark Lam
no flags Details | Formatted Diff | Diff
proposed patch. (6.72 KB, patch)
2017-07-07 12:29 PDT, Mark Lam
keith_miller: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peter van der Zee 2017-06-07 04:34:56 PDT
What steps will reproduce the problem?
1. eval("'\\\n\r'")

What is the expected output?

Uncaught SyntaxError: Invalid or unexpected token

What do you see instead?

A parser bug! :)

Description:

The spec explicitly treats `\r\n` as a single newline token rather than two but individual `\n` and `\r` characters cause individual newline tokens. When back-to-back `\n\r` causes two tokens. This is normally not very relevant, only to the point of line number reporting, but there's an edge case concerning so called "newline escapes" in single/double strings; Escaping a newline there takes this distinction into account and `'\\\r\n'` should be fine while `'\\\n\r'` should trigger an error on an unescaped `\r`.

See also https://bugs.chromium.org/p/v8/issues/detail?id=6401
Comment 1 Peter van der Zee 2017-06-07 04:36:14 PDT
r/newline escapes/line continuations
Comment 2 Mark Lam 2017-06-07 11:19:23 PDT
Seems like a simple thing to fix.  I'll take a look.
Comment 3 Mark Lam 2017-06-07 13:04:39 PDT
Created attachment 312213 [details]
proposed patch.

Let's try this on the EWS first.
Comment 4 Build Bot 2017-06-07 13:44:41 PDT
Comment on attachment 312213 [details]
proposed patch.

Attachment 312213 [details] did not pass jsc-ews (mac):
Output: http://webkit-queues.webkit.org/results/3889531

New failing tests:
stress/template-literal-line-terminators.js.ftl-eager
stress/template-literal-line-terminators.js.no-cjit-validate-phases
jsc-layout-tests.yaml/js/script-tests/parse-backslash-before-newline.js.layout-dfg-eager-no-cjit
stress/template-literal-line-terminators.js.ftl-no-cjit-no-inline-validate
stress/template-literal-line-terminators.js.ftl-eager-no-cjit
stress/template-literal-line-terminators.js.ftl-no-cjit-b3o1
stress/template-literal-line-terminators.js.default
jsc-layout-tests.yaml/js/script-tests/parse-backslash-before-newline.js.layout-ftl-no-cjit
stress/template-literal-line-terminators.js.no-cjit-collect-continuously
stress/template-literal-line-terminators.js.ftl-eager-no-cjit-b3o1
stress/template-literal-line-terminators.js.ftl-no-cjit-no-put-stack-validate
jsc-layout-tests.yaml/js/script-tests/parse-backslash-before-newline.js.layout-no-ftl
stress/template-literal-line-terminators.js.dfg-eager-no-cjit-validate
jsc-layout-tests.yaml/js/script-tests/parse-backslash-before-newline.js.layout-ftl-eager-no-cjit
stress/template-literal-line-terminators.js.no-llint
stress/template-literal-line-terminators.js.ftl-no-cjit-validate-sampling-profiler
stress/template-literal-line-terminators.js.dfg-maximal-flush-validate-no-cjit
jsc-layout-tests.yaml/js/script-tests/parse-backslash-before-newline.js.layout-no-cjit
jsc-layout-tests.yaml/js/script-tests/parse-backslash-before-newline.js.layout
jsc-layout-tests.yaml/js/script-tests/parse-backslash-before-newline.js.layout-no-llint
stress/template-literal-line-terminators.js.no-ftl
stress/template-literal-line-terminators.js.dfg-eager
stress/template-literal-line-terminators.js.ftl-no-cjit-small-pool
Comment 5 Build Bot 2017-06-07 14:03:28 PDT
Comment on attachment 312213 [details]
proposed patch.

Attachment 312213 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/3889656

New failing tests:
js/parse-backslash-before-newline.html
Comment 6 Build Bot 2017-06-07 14:03:29 PDT
Created attachment 312222 [details]
Archive of layout-test-results from ews102 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews102  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 7 Build Bot 2017-06-07 14:10:11 PDT
Comment on attachment 312213 [details]
proposed patch.

Attachment 312213 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/3889688

New failing tests:
js/parse-backslash-before-newline.html
Comment 8 Build Bot 2017-06-07 14:10:13 PDT
Created attachment 312223 [details]
Archive of layout-test-results from ews106 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 9 Build Bot 2017-06-07 14:22:56 PDT
Comment on attachment 312213 [details]
proposed patch.

Attachment 312213 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/3889691

New failing tests:
js/parse-backslash-before-newline.html
Comment 10 Build Bot 2017-06-07 14:22:58 PDT
Created attachment 312226 [details]
Archive of layout-test-results from ews117 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews117  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 11 Build Bot 2017-06-07 14:32:54 PDT
Comment on attachment 312213 [details]
proposed patch.

Attachment 312213 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/3889701

New failing tests:
js/parse-backslash-before-newline.html
Comment 12 Build Bot 2017-06-07 14:32:55 PDT
Created attachment 312229 [details]
Archive of layout-test-results from ews121 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews121  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.5
Comment 13 Mark Lam 2017-06-10 08:06:08 PDT
Created attachment 312570 [details]
proposed patch w/ updated test baselines.
Comment 14 Mark Lam 2017-06-10 08:58:21 PDT
Comment on attachment 312570 [details]
proposed patch w/ updated test baselines.

The patch applies properly: I tested applying it locally on another checkout.  The EWS patching system just does not like the \r in the patch.  Unfortunately, the nature of this fix is in the handling of \n\r.  So, I can't remove the use of \r in the test case.

Let's get the patch reviewed.
Comment 15 Yusuke Suzuki 2017-06-10 10:20:48 PDT
Comment on attachment 312570 [details]
proposed patch w/ updated test baselines.

View in context: https://bugs.webkit.org/attachment.cgi?id=312570&action=review

> Source/JavaScriptCore/parser/Lexer.cpp:708
>      // Allow both CRLF and LFCR.

Let's change this comment.

> Source/JavaScriptCore/parser/Lexer.cpp:1416
>              ++m_lineNumber;

I think now this LineNumberAdder is not necessary. This is added to increnting one line number with <LF><CR> while normalizing them as <LF><LF>.
However, now, our Lexer does not accept `<LF><CR>` as one line terminator. Thus, I think we can discard this class!
Comment 16 Mark Lam 2017-06-10 10:49:12 PDT
(In reply to Yusuke Suzuki from comment #15)
> Comment on attachment 312570 [details]
> proposed patch w/ updated test baselines.
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=312570&action=review
> 
> > Source/JavaScriptCore/parser/Lexer.cpp:708
> >      // Allow both CRLF and LFCR.
> 
> Let's change this comment.

I deleted the comment.  I think the code now says what is allowed clearly enough.

> > Source/JavaScriptCore/parser/Lexer.cpp:1416
> >              ++m_lineNumber;
> 
> I think now this LineNumberAdder is not necessary. This is added to
> increnting one line number with <LF><CR> while normalizing them as <LF><LF>.
> However, now, our Lexer does not accept `<LF><CR>` as one line terminator.
> Thus, I think we can discard this class!

Thanks.  Fixed.
Comment 17 Yusuke Suzuki 2017-07-06 02:16:24 PDT
How about this patch?
Comment 18 Mark Lam 2017-07-06 15:01:03 PDT
(In reply to Yusuke Suzuki from comment #17)
> How about this patch?

I'm still working thru some test failures.  This is a low priority task for me, but I'm trying to wrap it up.
Comment 19 Mark Lam 2017-07-07 12:29:08 PDT
Created attachment 314859 [details]
proposed patch.

This patch has passed the JSC and layout tests on my local runs.
Comment 20 Keith Miller 2017-07-07 12:43:52 PDT
Comment on attachment 314859 [details]
proposed patch.

r=me.
Comment 21 Mark Lam 2017-07-07 12:51:30 PDT
Thanks for the review.  Landed in r219263: <http://trac.webkit.org/r219263>.