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

Bug 443841

Summary: orion/editor/edit.js contains an invalid regex
Product: [ECD] Orion Reporter: Brian Svihovec <svihovec>
Component: EditorAssignee: Grant Gayed <grant_gayed>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mamacdon
Version: 6.0   
Target Milestone: 7.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Brian Svihovec CLA 2014-09-11 10:58:11 EDT
line 284 has:

contentType = contentType.replace(/[*|:/".<>?+]/g, '_');

It looks like the /" needs to be either \" or \/"
Comment 1 Mark Macdonald CLA 2014-09-11 12:17:18 EDT
The code is in orion/editor/edit.js. 

It is valid ES5, since an unescaped slash is allowed to appear in a regex literal as long as it's inside a character class:
>   /[/]/.test("/")   // true

In ES3 the same code is illegal.

We could escape it, for the sake of compatibility, but I'd like to know more about how you found this. Are you trying to parse this code with an older version of Rhino, or something else that doesn't handle ES5?
Comment 2 Brian Svihovec CLA 2014-09-11 12:46:08 EDT
Mark,

You are right, it is in edit.js, although the line does not appear to be the same as you mentioned.

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/tree/bundles/org.eclipse.orion.client.editor/web/orion/editor/edit.js?id=R6_0  

See line 284.  Also, this looks like line 283 in the Master branch.

You are also right about the fact that we are using an older parser.  I am not sure of the exact version of the parser, but it is part of the Dojo 1.7.5 build that we are using to package our application.

I am fine with changing the file in my local version for our specific needs.  Based on your comment, I believe the resolution would be \/" to escape the forward slash?

Finally, other issues I have seen that are probably related include:
1) the use of 'char' as a variable name (i.e. var char)
2) the use of 'new' as a field name in an object (i.e. e.new[0])
3) the use of 'transient' as a field name in an object (i.e. foo.transient)

Again, I am fine with changing these locally until we move up to a newer parser.
Comment 3 Mark Macdonald CLA 2014-09-12 12:36:58 EDT
(In reply to Brian Svihovec from comment #2)
> Based on your comment, I believe the resolution would be \/" to escape the
> forward slash?

Yes.

> Finally, other issues I have seen that are probably related include:
> 1) the use of 'char' as a variable name (i.e. var char)
> 2) the use of 'new' as a field name in an object (i.e. e.new[0])
> 3) the use of 'transient' as a field name in an object (i.e. foo.transient)

Yes: ES5 has relaxed the use of restricted keywords a bit.

> Again, I am fine with changing these locally until we move up to a newer
> parser.

That is probably your best bet. Or if possible, set the Dojo builder to ES5 mode somehow. It's probably picking up Rhino through the JRE, so IIRC you will need Java 7 (Java 6 ships with an ancient version of Rhino). They seem to be using Closure compiler too, which gave us a lot of grief in the Orion build. Try the flag --language_in=ECMASCRIPT5 or [1] if they're invoking it programmatically.
Comment 5 Mark Macdonald CLA 2014-09-12 12:57:22 EDT
I'm keeping this bug open for issue #2 from comment 2:
> 2) the use of 'new' as a field name in an object (i.e. e.new[0])

This is the only syntactic issue Brian raised that appears to cause problems in IE7/8 (everything else was tolerated). When running IE in compatibility mode, this does not parse:

> ({'new': '1'}).new[0];    // Error: Expected identifier

Brian, do you know offhand which file that was in? If it's anywhere under /bundles/org.eclipse.orion.client.editor/ then we should fix it. The editor is supposed to work in older versions of IE.
Comment 6 Brian Svihovec CLA 2014-09-15 09:22:31 EDT
It looks like .new was being used in markdownEditor.js
Comment 7 Grant Gayed CLA 2014-09-18 12:00:46 EDT
(In reply to Brian Svihovec from comment #6)
> It looks like .new was being used in markdownEditor.js

This currently is only usable in the context of Orion, so it's not a must-fix.  However I've made the change anyways since it's easy and I'd like to see this functionality exposed outside of Orion one of these days.  The commit: http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=ff0d4c2b093551d86feddfa3951b397e30c78b00 .

Looking at comment 5, I think this was the last issue that we planned to address in Orion, so closing report.  If I'm wrong on this then please reopen.