Bug 336579 - [validation] Regular Expression Error Handling Improvement Request
Summary: [validation] Regular Expression Error Handling Improvement Request
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: 3.2.3   Edit
Hardware: All All
: P3 normal with 2 votes (vote)
Target Milestone: Future   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords: plan
Depends on:
Blocks:
 
Reported: 2011-02-07 21:21 EST by Paul Beusterien CLA
Modified: 2014-05-29 13:52 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Beusterien CLA 2011-02-07 21:21:58 EST
For the following one line program 

var re = /^[^:/]+:\/\/[^/]+\/?/;

JSDT generates the following 5 errors :

Description	Resource	Path	Location	Type
Syntax error on token "Invalid Character", delete this token	re.js	/re	line 1	JavaScript Problem
Syntax error on tokens, ArrayLiteralHeader expected instead	re.js	/re	line 1	JavaScript Problem
Syntax error on tokens, ArrayLiteralHeader expected instead	re.js	/re	line 1	JavaScript Problem
Syntax error on tokens, ArrayLiteralHeader expected instead	re.js	/re	line 1	JavaScript Problem
Syntax error on tokens, ArrayLiteralHeader expected instead	re.js	/re	line 1	JavaScript Problem


JSLint generates the much more understandable:

Error:
Problem at line 1 character 30: Unescaped '/'.

var re = /^[^:/]+:\/\/[^/]+\/?/;

Problem at line 1 character 40: Unescaped '/'.

var re = /^[^:/]+:\/\/[^/]+\/?/;

Adding backslashes before the two internal forward slashes make both parsers happy.

See also https://github.com/jquery/jquery-mobile/issues/issue/1010
Comment 1 Chris Jaun CLA 2013-10-23 17:49:59 EDT
I notice in the current 3.6, we don't generate any errors for this, even though JSlint does.

Possible that bug404832 over corrected the error messages seen there.
Comment 2 Victor Rubezhny CLA 2013-11-20 10:44:23 EST
I can confirm that fix for the bug #404832 also fixes this issue.
Comment 3 Chris Jaun CLA 2013-11-20 10:56:22 EST
My concern is that we seem to no longer being showing an actual error as identified by JSLint.
Comment 4 Victor Rubezhny CLA 2013-11-20 11:29:47 EST
Chris, do you see some error in that RegEx?
Comment 5 Chris Jaun CLA 2013-11-20 13:54:02 EST
If you run it though JSLint, you see errors, as the submitter stated.
Comment 6 Victor Rubezhny CLA 2013-11-20 14:08:36 EST
Chris, JSLint shows errors even for a 'good' pattern /^[^:\/]+:\/\/[^\/]+\/?/ (taken from https://github.com/jquery/jquery-mobile/commit/1c9414d0306d415f953ce3695fecba186ff6178f). 

Java Pattern.compile() say no errors on both patterns ("bad" /^[^:/]+:\/\/[^/]+\/?/ and "good" /^[^:\/]+:\/\/[^\/]+\/?/) and both patterns work well with Patern.compile. 

Also, the following script block also works well in my FF and there are no errors in Web Console: 

<script type="text/javascript">
var ua = "http://www.google.com/somefolder/somefile.html";
var ur = "/somefolder/somefile.html";

var pb = /^[^:/]+:\/\/[^/]+\/?/;
var pg = /^[^:\/]+:\/\/[^\/]+\/?/;

var mab = ua.search(pb);
var mag = ua.search(pg);
var mrb = ur.search(pb);
var mrg = ur.search(pg);

window.alert("Search in '" + ua + "' by 'bad' pattern /^[^:/]+:\/\/[^/]+\/?/ == " + mab + "\n" +
"Search in '" + ua + "' by 'good' pattern /^[^:\/]+:\/\/[^\/]+\/?/ == " + mag + "\n" +
"Search in '" + ur + "' by 'bad' pattern /^[^:/]+:\/\/[^/]+\/?/ == " + mrb + "\n" +
"Search in '" + ur + "' by 'good' pattern /^[^:\/]+:\/\/[^\/]+\/?/ == " + mrg);
</script>

So, probably both RegExps are valid.

Looks like jQuery guys just made a workaround to bug #404832 in their code, but not their own error fixing.
Comment 7 Victor Rubezhny CLA 2013-11-20 14:43:27 EST
I cannot find any restrictions on using unescaped '/'-character in ClassRanges (between '[' and ']') in "ECMAScript Language
Specification ECMA-262, 5.1 Edition, June 2011" (clause 15.10).

"15.10.2.18 ClassAtomNoDash
The production ClassAtomNoDash :: SourceCharacter but not one of \ or ] or - evaluates by returning a one-element CharSet containing the character represented by SourceCharacter."

So, the only \ ] and - characters are to be escaped inside a ClassRange. All other non-whitespace chaacters are allowed to be unescaped including forward slash (/) character.


Escaped forward character (\/) means the same as the forward character itself (/) - IMHO, that's why my test script in FF works well and Pattern.compile() works well for both escaped and unescaped variations of the pattern.