Bug 241647 - [validation] JSDT doesn’t understand multi-line strings
Summary: [validation] JSDT doesn’t understand multi-line strings
Status: RESOLVED FIXED
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows Vista
: P2 major (vote)
Target Milestone: 3.2.3   Edit
Assignee: Chris Jaun CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks: 326346
  Show dependency tree
 
Reported: 2008-07-22 07:19 EDT by Laurens Holst CLA
Modified: 2010-09-27 18:21 EDT (History)
3 users (show)

See Also:
thatnitind: review+


Attachments
Testcase (326 bytes, text/javascript)
2010-01-10 20:28 EST, Laurens Holst CLA
thatnitind: iplog+
Details
Fix (5.11 KB, patch)
2010-01-10 20:30 EST, Laurens Holst CLA
thatnitind: iplog+
Details | Diff
Fix (part 2) (1.52 KB, patch)
2010-01-10 20:31 EST, Laurens Holst CLA
thatnitind: iplog+
Details | Diff
patch (7.72 KB, patch)
2010-08-27 15:10 EDT, Chris Jaun CLA
no flags Details | Diff
new patch (3.63 KB, patch)
2010-09-27 14:00 EDT, Chris Jaun CLA
no flags Details | Diff
Updated patch (7.72 KB, patch)
2010-09-27 15:21 EDT, Chris Jaun CLA
cmjaun: iplog+
Details | Diff
JUnits (4.12 KB, patch)
2010-09-27 15:24 EDT, Nitin Dahyabhai CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Laurens Holst CLA 2008-07-22 07:19:44 EDT
Build ID: I20080617-2000

JSDT doesn’t understand multi-line strings. In the following example, you will get an error ‘String literal is not properly closed by a double-quote’, even though it should just work.

Also, the error description seems incorrect as in JS strings can use both single and double-quotes.

Example:

var xslt = new DOMParser().parseFromString('\
    <xsl:stylesheet version="1.0"\
        xmlns="http://www.w3.org/1999/xhtml"\
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\
        <xsl:output method="html" indent="no"/>\
        <xsl:template match="/">\
            <div>\
                <xsl:apply-templates select="*" />\
            </div>\
        </xsl:template>\
    </xsl:stylesheet>\
');

~Grauw
Comment 1 Chris Jaun CLA 2009-03-16 15:55:48 EDT
The multi-line string example shown is a violation of the spec. An escape character is not allowed before a line break. 

I do, however, realize that most browsers support this practice. 

I plan to do two things to address this bug:

1. Fix the error message.
2. Validation will remain in place to catch this problem, but a preference can be added allowing you to switch this error to a warning or ignore.
Comment 2 Laurens Holst CLA 2009-03-16 20:46:42 EDT
For what it’s worth, the ECMAScript 3.1 draft does specify this currently (page 20 in my local version, see LineContinuation key in the syntax).

It would already help if this was parsed correctly, even if it triggers an error message, so that it does not mess up further parsing :).

Personally, by the way, I would consider this de facto Javascript behaviour, and not have it trigger an error at all (at least not by default).
Comment 3 Chris Jaun CLA 2009-09-15 10:50:02 EDT
Categorizing JSDT bugzillas for planning purposes.
Comment 4 Laurens Holst CLA 2010-01-10 09:22:12 EST
ECMAScript 5, now a standard, describes this syntax in section 7.8.4, the LineContinuation production.
Comment 5 Laurens Holst CLA 2010-01-10 20:28:45 EST
Created attachment 155691 [details]
Testcase

Somewhat extensive testcase.
Comment 6 Laurens Holst CLA 2010-01-10 20:30:01 EST
Created attachment 155692 [details]
Fix

Part 1 of the fix, org.eclipse.wst.jsdt.core module.

See also http://hg.grauw.nl/org.eclipse.wst.jsdt.core/rev/a2d8ce10d2da
Comment 7 Laurens Holst CLA 2010-01-10 20:31:08 EST
Created attachment 155693 [details]
Fix (part 2)

Part 2 of the fix, org.eclipse.wst.jsdt.ui module.

See also http://hg.grauw.nl/org.eclipse.wst.jsdt.ui/rev/700917937ad0
Comment 8 Laurens Holst CLA 2010-01-10 20:34:04 EST
So I fixed this. Part 1 takes care of the AST parser, part 2 takes care of the syntax highlighting.

There’s a lot of code duplication between Scanner and PublicScanner in core btw. Is the latter still used? When I added breakpoints they didn’t get triggered. Anyway, I copied the code there, too.
Comment 9 Laurens Holst CLA 2010-01-26 11:45:45 EST
Comment on attachment 155693 [details]
Fix (part 2)

Setting review flag to get some movement here.
Comment 10 Chris Jaun CLA 2010-01-26 13:15:11 EST
Thanks for the patch Laurens.

3.2m5 is already in shutdown mode, so I targeted this for the next milestone, m6.

Chris
Comment 11 Chris Jaun CLA 2010-02-26 10:06:49 EST
Nitin, this is flagged to be reviewed by you.

Can you take a look at this, so we can get it in m6?
Comment 12 Laurens Holst CLA 2010-05-05 07:59:15 EDT
This patch only needs to be reviewed and checked in. What’s holding it up?
Comment 13 Nitin Dahyabhai CLA 2010-05-05 08:15:49 EDT
Partly it's the "part 1" part, where the original js.g file changes aren't present so we can't actually regenerate a version with your changes when we make other updates to it, but also because we don't have an answer to your question in comment 8, and I don't like changing the parser in later milestones.
Comment 14 Laurens Holst CLA 2010-05-05 08:39:36 EDT
(In reply to comment #13)
> Partly it's the "part 1" part, where the original js.g file changes aren't
> present so we can't actually regenerate a version with your changes when we
> make other updates to it,

Really, those are generated files? It doesn’t look like that, with all those in-line comments...

> but also because we don't have an answer to your
> question in comment 8,

The code I mentioned in comment 8 is virtually identical to the other code, so even if it is still used, I don’t think there is reason to believe it would not work there. (Also, then you would have a big code duplication issue.)

Nevertheless I understand that you would want to verify this.

> and I don't like changing the parser in later milestones.

Meh, I submitted the patch in January, 4 months ago… Anyway, I’m looking forward to seeing it in the next version then.

Thanks for your quick response!
Comment 15 Nitin Dahyabhai CLA 2010-05-18 12:17:30 EDT
(In reply to comment #14)
> (In reply to comment #13)
> > Partly it's the "part 1" part, where the original js.g file changes aren't
> > present so we can't actually regenerate a version with your changes when we
> > make other updates to it,
> 
> Really, those are generated files? It doesn’t look like that, with all those
> in-line comments...

It's possible.  The directions for regenerating the JavaScript parser aren't as simple as they are for our other languages.  We'll look at this in 3.2.1.
Comment 16 Nitin Dahyabhai CLA 2010-06-13 21:52:23 EDT
Rescheduled 3.2.1 is too short, moving to 3.2.2.
Comment 17 Chris Jaun CLA 2010-08-27 15:08:02 EDT
Laurens,

In public scanner you updated the scanEscapeCharacter() to always return false.

Shoulddn't one of those return statements be true?

Chris
Comment 18 Chris Jaun CLA 2010-08-27 15:10:07 EDT
Created attachment 177640 [details]
patch

Regenerated the patch so that it applies correctly in the 3_2_maintenance branch.

Made no changes to the content.
Comment 19 domcap CLA 2010-09-02 08:44:04 EDT
Hi There,

I'm running an Eclipse Helios patched with the most recent WTP 3.2.2 maintenance release (as of August 28th, 2010) and I still see errors for multi-line strings. Is there a setting I have to change to not see this, or has this still not been integrated at the present time?

Thanks, Dominic.
Comment 20 Chris Jaun CLA 2010-09-07 10:35:31 EDT
(In reply to comment #19)
> Hi There,
> 
> I'm running an Eclipse Helios patched with the most recent WTP 3.2.2
> maintenance release (as of August 28th, 2010) and I still see errors for
> multi-line strings. Is there a setting I have to change to not see this, or has
> this still not been integrated at the present time?
> 
> Thanks, Dominic.

This bug is not in resolved state, meaning no code has been checked in.

The patch has been reviewed and there was a question posted for the patch submitter that we are awaiting a response on.

Chris
Comment 21 Chris Jaun CLA 2010-09-27 14:00:27 EDT
Created attachment 179672 [details]
new patch
Comment 22 Laurens Holst CLA 2010-09-27 14:28:16 EDT
(In reply to comment #17)
> In public scanner you updated the scanEscapeCharacter() to always return false.
> 
> Shoulddn't one of those return statements be true?

Hey, sorry for the late reply,

Yes, looks like you’re right, the latter one should return true.

Thanks,

Laurens
Comment 23 Laurens Holst CLA 2010-09-27 14:31:38 EDT
Do you want me to post an updated patch or can you just make the above mentioned change before checking in? (I don’t really have an up-to-date tree so it would be convenient :).)
Comment 24 Laurens Holst CLA 2010-09-27 14:46:22 EDT
That new patch you just posted doesn’t seem right. It seems like it only contains part of the changes from fix (part 1).

(Also, I see I mentioned in comment 8 that I couldn’t get the PublicScanner code to run, so that explains why it wasn’t tested and the error snuck in :). Sharp eyes!)
Comment 25 Chris Jaun CLA 2010-09-27 15:21:58 EDT
Created attachment 179680 [details]
Updated patch

Changed false to true in PublicScanner.
Comment 26 Nitin Dahyabhai CLA 2010-09-27 15:24:48 EDT
Created attachment 179681 [details]
JUnits
Comment 27 Chris Jaun CLA 2010-09-27 15:34:39 EDT
Checked into 3.2.3 and HEAD.
Comment 28 Laurens Holst CLA 2010-09-27 18:21:52 EDT
Wonderful!