Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352108 - [formatter] Regex can confuse javascript formatter
Summary: [formatter] Regex can confuse javascript formatter
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-14 11:08 EDT by Edward Winkelman CLA
Modified: 2013-06-19 11:11 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 Edward Winkelman CLA 2011-07-14 11:08:05 EDT
Build Identifier: 20110615-0604

Inclusion of certain regex expressions can cause the javascript formatter to get confused, start wrapping lines and indenting unnecessarily.  An example using a jQuery excerpt that performs e-mail validation:

$(document).ready(function() {
var emailRegEx = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.([a-z][a-z]+)|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
  $('#email').keyup(function() {
      if (!emailRegEx.test(('#email').value)) {
        alert('Bad e-mail address');
      }
  });
});


Reproducible: Always

Steps to Reproduce:
1. Enter the above regex into a javascript file
2. Press ctrl-shift-f to trigger the formatter
Comment 1 Edward Winkelman CLA 2011-07-14 11:09:12 EDT
NB: The regex is entered all on one line
Comment 2 Nitin Dahyabhai CLA 2011-07-14 17:05:33 EDT
NB?
Comment 3 Edward Winkelman CLA 2011-07-15 12:02:39 EDT
(In reply to comment #2)
> NB?

NB means note well.

As an admendum, apparently this doesn't happen in pure JS files.  Only when the javascript is part of a JSP (and therefore also subject to the JSP editor)
Comment 4 Nitin Dahyabhai CLA 2011-07-15 17:44:40 EDT
You've made sure the settings for HTML content allow for lines that long?
Comment 5 Edward Winkelman CLA 2011-07-18 13:19:00 EDT
(In reply to comment #4)
> You've made sure the settings for HTML content allow for lines that long?

I have word wrap set at the same for all of the editors (120 characters in this case).  That particular line is too long, but it shouldn't cause the lines before and after it to start indenting and wrapping themselves.
Comment 6 Bruce Edge CLA 2011-11-09 23:35:27 EST
Here's another one that trips the js regex validator:

/^(|[A-Za-z0-9/+]{40})$/


Multiple markers at this line
	- Syntax error, insert "}" to complete ObjectLiteral
	- Syntax error on token "]", delete this token
	- Syntax error on token ",", invalid (
	- Syntax error on token "40", delete this token
	- Syntax error, insert ")" to complete Arguments
	- Missing semicolon
	- Syntax error, insert "}" to complete MethodBody