deblondon / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

Double-slash in JS regex turns into a comment #217

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Run Prettify on:

if(!/^https?:\/\//.test(val) && foo == 'bar') {
    val = 'http://' + val;
}

What is the expected output?  What do you see instead?
The "\//" should be treated as an escaped-slash+regex end. Instead, it is 
treated as a comment and the rest of the line is commented out.

(example output 
http://meta.stackoverflow.com/questions/132935/javascript-regex-syntax-highlight
ing-issue#132935)

What version are you using?  On what browser?
Latest 
(http://meta.stackoverflow.com/content/js/prettify-full.js?v=4ed9aa4b8d0e)

Please provide any additional information below.

Original issue reported on code.google.com by manishsm...@gmail.com on 18 May 2012 at 9:46

GoogleCodeExporter commented 8 years ago
Thanks for the small testcase.

"if(/^https?:\/\//" prettified ok as did "if( !/^https?:\/\//" so it was a 
problem with greedy runs of punctuation consuming the token that would 
otherwise trigger the ("/" starts regex instead of division operator after 
token) rule.

Fixed in r279.
Testcase 
http://google-code-prettify.googlecode.com/svn/trunk/tests/prettify_test_2.html#
issue217

Original comment by mikesamuel@gmail.com on 25 Feb 2013 at 5:28