Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 319900 - StringLiteral#setLiteralValue needlessly escapes apostrophes (')
Summary: StringLiteral#setLiteralValue needlessly escapes apostrophes (')
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows Vista
: P3 minor (vote)
Target Milestone: 3.6.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-14 14:51 EDT by Chris West (Faux) CLA
Modified: 2010-08-26 05:49 EDT (History)
3 users (show)

See Also:
srikanth_sankaran: review+


Attachments
Remove the "case '" clause (616 bytes, patch)
2010-07-14 14:55 EDT, Chris West (Faux) CLA
Olivier_Thomann: iplog+
Details | Diff
Proposed fix + regression tests (2.05 KB, patch)
2010-07-15 10:56 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris West (Faux) CLA 2010-07-14 14:51:12 EDT
Build Identifier: N20100703-2000

Calling setLiteralValue() with a String containing a single-quote will result in the quote being escaped in the rewritten output.

i.e. sl.setLiteralValue(sl.getLiteralValue() + " loves horses' manes") results in ...horses\' manes", which is correct, but ugly.

Easy enough to work around by copy-pastaing the method and removing the offending case, as patch.

Reproducible: Always

Steps to Reproduce:
1. Execute:
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.StringLiteral;

class JDTScratch {
  public static void main(String[] args) {
    StringLiteral sl = ast().newStringLiteral();

    sl.setEscapedValue("\"'\"");
    System.out.println(sl.getEscapedValue()); // "'"

    sl.setLiteralValue("'");
    System.out.println(sl.getEscapedValue()); // "\'"
  }

  static AST ast() {
    final ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(new char[0]);
    return parser.createAST(null).getAST();
  }
}


Observe output, as comments.
Comment 1 Chris West (Faux) CLA 2010-07-14 14:55:07 EDT
Created attachment 174331 [details]
Remove the "case '" clause
Comment 2 Olivier Thomann CLA 2010-07-15 10:47:03 EDT
The quote must be escaped only within a character literal.
Comment 3 Olivier Thomann CLA 2010-07-15 10:55:35 EDT
Srikanth, we should fix this for 3.6.1 as we corrupt the string literal.

Released for 3.7M1.
Comment 4 Olivier Thomann CLA 2010-07-15 10:56:03 EDT
Created attachment 174405 [details]
Proposed fix + regression tests
Comment 5 Olivier Thomann CLA 2010-07-15 10:56:16 EDT
Same patch with regression tests.
Comment 6 Srikanth Sankaran CLA 2010-07-18 23:56:24 EDT
Patch looks good.
Comment 7 Olivier Thomann CLA 2010-07-19 13:01:35 EDT
Released for 3.6.1 with updated copyright for the test.
Comment 8 Satyam Kandula CLA 2010-08-03 05:23:14 EDT
Verified for 3.7M1 using build I20100802-1800
Comment 9 Satyam Kandula CLA 2010-08-05 04:40:47 EDT
Change status to RESOLVED as this needs to be reverified for 3.6.1.
Comment 10 Satyam Kandula CLA 2010-08-26 05:49:43 EDT
Verified for 3.6.1 RC2 using Build id: M20100825-0800