Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 326449

Summary: parser error on regular expression containing sequence [/]
Product: [WebTools] JSDT Reporter: Jim Zhang <jzhang>
Component: GeneralAssignee: Jason Peterson <jasonpet>
Status: RESOLVED FIXED QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3 CC: cbridgha, cmjaun, Olivier_Thomann, paul.beusterien
Version: unspecifiedFlags: jasonpet: pmc_approved? (david_williams)
jasonpet: pmc_approved? (raghunathan.srinivasan)
jasonpet: pmc_approved? (naci.dai)
jasonpet: pmc_approved? (neil.hauge)
cbridgha: pmc_approved+
jasonpet: pmc_approved? (kaloyan)
cmjaun: review+
Target Milestone: 3.5.1   
Hardware: All   
OS: All   
Whiteboard: PMC_approved

Description Jim Zhang CLA 2010-09-28 14:37:49 EDT
Build Identifier: WTP 3.2

The following statement contains a valid reg expression:

searchStr.replace(/\n( |\t)*[/][/]/g,'//');

but the parser complains that the token "]" in the sequence "[/]" is unexpected.

Reproducible: Always
Comment 1 Chris Jaun CLA 2010-11-09 11:51:26 EST
I do not believe that is a valid regular expression statement.

You close the expression here [/] and then keep going.
Comment 2 Jim Zhang CLA 2010-11-10 11:41:47 EST
The expression was valid. The square brackets make "/" literal characters instead of the delimiter.  Try the following sample code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test1</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<script type="text/javascript">
var searchStr = ">\n //<";
alert(searchStr);
searchStr = searchStr.replace(/\n( |\t)*[/][/]/g,'//');
alert(searchStr);
</script>
</body>
</html>

Re-opening.
Comment 3 Jason Peterson CLA 2013-08-23 10:19:45 EDT
I also ran into this same issue with jQuery mobile 1.3.2 and jQuery mobile 1.4.0 alpha 2.

Here is the expression causing the parser error:

 /([!"#$%&'()*+,./:;<=>?@[\]^`{|}~])/g
Comment 5 Jason Peterson CLA 2013-08-26 10:01:07 EDT
Give a brief technical overview. Who has reviewed this fix? 
- Syntax errors are thrown if the parser encounters the regular expression delimiter (/) within a character class ([...]).  Characters should be treated as literal characters within the brackets.
- This has been reviewed by the project lead.

How has the fix been tested? 
-  I have manually tested this and created new JUnits.  Entire JUnit suite has been run.

Is there a test case attached to the bugzilla record? Has a JUnit Test been added? 
-  Yes, JUnits have been added

What is the risk associated with this fix? 
- Minimal to no risk
Comment 6 Chuck Bridgham CLA 2013-08-26 10:18:20 EDT
looks good.. thanks
Comment 7 Chris Jaun CLA 2013-08-28 17:33:17 EDT
Delivered to 3.5.1 and master.