Revision: 8356
Author: rj...@google.com
Date: Fri Jul 2 08:22:57 2010
Log: UiBinderWriter#escapeTextForJavaStringLiteral correctly escapes \n and
", but forgets \.
Also, I couldn't see a reason for using replaceAll instead of replace.
Patch by tbro...@gmail.com
Review by rj...@google.com
http://gwt-code-reviews.appspot.com/620804
Review by: robertvaw...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8356
Modified:
/trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
/trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
/trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
=======================================
--- /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java Mon
Jun 7 12:20:31 2010
+++ /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java Fri
Jul 2 08:22:57 2010
@@ -113,11 +113,12 @@
/**
* Escape characters that would mess up interpretation of this string as
a
- * string literal in generated code (that is, protect \n and " ).
+ * string literal in generated code (that is, protect \, \n and " ).
*/
public static String escapeTextForJavaStringLiteral(String text) {
- text = text.replaceAll("\"", "\\\\\"");
- text = text.replaceAll("\n", "\\\\n");
+ text = text.replace("\\", "\\\\");
+ text = text.replace("\"", "\\\"");
+ text = text.replace("\n", "\\n");
return text;
}
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
Tue Jun 22 06:26:45 2010
+++ /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
Fri Jul 2 08:22:57 2010
@@ -231,19 +231,19 @@
public void testDomAttributeMessageWithFunnyChars() {
ParagraphElement p = widgetUi.funnyCharsMessageDomAttributeParagraph;
String t = p.getAttribute("title");
- assertEquals("funny characters \" ' ' & < > > { }", t);
+ assertEquals("funny characters \\ \" ' ' & < > > { }", t);
}
public void testDomAttributeNoMessageWithFunnyChars() {
ParagraphElement p = widgetUi.funnyCharsDomAttributeParagraph;
String t = p.getAttribute("title");
- assertEquals("funny characters \" ' ' & < > > { }", t);
+ assertEquals("funny characters \\ \" ' ' & < > > { }", t);
}
public void testDomTextMessageWithFunnyChars() {
String t = widgetUi.funnyCharsMessageParagraph.getInnerText();
assertEquals("They might show up in body text that has been marked
for "
- + "translation: funny characters \" \" ' ' & < > > { }", t);
+ + "translation: funny characters \\ \" \" ' ' & < > > { }", t);
}
public void testEmptyAttributesOkay() {
@@ -275,12 +275,12 @@
public void testProtectedDomTextMessageWithFunnyChars() {
String t = widgetUi.funnyCharsProtectedMessageParagraph.getInnerText();
assertEquals("Don't forget about protected untranslatable blocks: "
- + "funny characters \" \" ' ' & < > > { }", t);
+ + "funny characters \\ \" \" ' ' & < > > { }", t);
}
public void testDomTextInNamedElementMessageWithFunnyChars() {
String t = widgetUi.funnyCharsMessageChildSpan.getInnerText();
- assertEquals("funny characters \" \" ' ' & < > > { }", t);
+ assertEquals("funny characters \\ \" \" ' ' & < > > { }", t);
}
public void
suppressedForSafari3Fail_testDomTextNoMessageWithFunnyChars() {
@@ -289,7 +289,7 @@
String t = p.getInnerHTML().replace("\n", " ").toLowerCase();
String expected = "Templates can be marked up for <b>localization</b>,
which presents alls "
+ "kinds of exciting opportunities for bugs related to character
escaping. "
- + "Consider these funny characters \" \" ' ' & < > >
{ }, and "
+ + "Consider these funny characters \\ \" \" ' ' & < >
> { }, and "
+ "the various places they might make your life miserable, like
this "
+ "untranslated paragraph.";
expected = expected.toLowerCase();
@@ -448,13 +448,13 @@
public void testWidgetAttributeMessageWithFunnyChars() {
ClickyLink clicky = widgetUi.funnyCharsMessageAttributeWidget;
String t = clicky.getPopupText();
- assertEquals("funny characters \" ' ' & < > > { }", t);
+ assertEquals("funny characters \\ \" ' ' & < > > { }", t);
}
public void testWidgetAttributeNoMessageWithFunnyChars() {
ClickyLink clicky = widgetUi.funnyCharsAttributeWidget;
String t = clicky.getPopupText();
- assertEquals("funny characters \" ' ' & < > > { }", t);
+ assertEquals("funny characters \\ \" ' ' & < > > { }", t);
}
public void testCustomImageClass() {
=======================================
---
/trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
Fri Apr 2 07:37:08 2010
+++
/trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
Fri Jul 2 08:22:57 2010
@@ -443,35 +443,35 @@
<h2>Localization and character escaping</h2>
<p ui:field="funnyCharsParagraph">Templates can be marked up for
<b>localization</b>,
which presents alls kinds of exciting opportunities for bugs related
to
- character escaping. Consider these funny characters " " ' '
& < > > { },
+ character escaping. Consider these funny characters \ " " '
' & < > > { },
and the various places they might make your life miserable, like this
untranslated paragraph.</p>
<p ui:field="funnyCharsMessageParagraph"><ui:msg>They might show up
- in body text that has been <b>marked for translation</b>: funny
characters " " ' ' & < > > { }</ui:msg></p>
- <p><ui:msg>Or perhaps in a subelement with a ui:field: <span
ui:field='funnyCharsMessageChildSpan'>funny characters " " ' '
& < > > { }</span></ui:msg></p>
- <p ui:field="funnyCharsProtectedMessageParagraph"><ui:msg>Don't
forget about protected untranslatable blocks: <ui:ph name='francine'>funny
characters " " ' ' & < > > { }</ui:ph></ui:msg></p>
- <p ui:field="funnyCharsMessageDomAttributeParagraph" title="funny
characters " ' ' & < > > { }">
+ in body text that has been <b>marked for translation</b>: funny
characters \ " " ' ' & < > > { }</ui:msg></p>
+ <p><ui:msg>Or perhaps in a subelement with a ui:field: <span
ui:field='funnyCharsMessageChildSpan'>funny characters \ " " ' '
& < > > { }</span></ui:msg></p>
+ <p ui:field="funnyCharsProtectedMessageParagraph"><ui:msg>Don't
forget about protected untranslatable blocks: <ui:ph name='francine'>funny
characters \ " " ' ' & < > > { }</ui:ph></ui:msg></p>
+ <p ui:field="funnyCharsMessageDomAttributeParagraph" title="funny
characters \ " ' ' & < > > { }">
<ui:attribute name="title"/>
Attributes of dom elements can be translated too, like the
tooltip of this paragraph, which features the challenging
characters.
</p>
<p ui:field="funnyCharsDomAttributeParagraph"
- title="funny characters " ' ' & < > > { }">
+ title="funny characters \ " ' ' & < > > { }">
They might also appear in an unstranslated attribute of a dom
element, like
the tooltip for this paragraph.
</p>
<p>And all the cases above apply to widgets as well:</p>
- <gwt:Label>I am an untranslatable HasText with funny characters "
" ' ' & < > > { }</gwt:Label>
- <gwt:HTML>I am an untranslatable HasHTML with funny characters "
" ' ' & < > > { }</gwt:HTML>
- <gwt:Label><ui:msg>I am a translatable <ui:ph name="widgetType"
example="myWidget">HasText</ui:ph> with funny characters " " ' '
& < > > { }</ui:msg></gwt:Label>
- <gwt:HTML><ui:msg>I am a translatable <ui:ph name="widgetType"
example="myWidget">HasHTML</ui:ph> with funny characters " " ' '
& < > > { }</ui:msg></gwt:HTML>
+ <gwt:Label>I am an untranslatable HasText with funny characters \ "
" ' ' & < > > { }</gwt:Label>
+ <gwt:HTML>I am an untranslatable HasHTML with funny characters \ "
" ' ' & < > > { }</gwt:HTML>
+ <gwt:Label><ui:msg>I am a translatable <ui:ph name="widgetType"
example="myWidget">HasText</ui:ph> with funny characters \ " " ' '
& < > > { }</ui:msg></gwt:Label>
+ <gwt:HTML><ui:msg>I am a translatable <ui:ph name="widgetType"
example="myWidget">HasHTML</ui:ph> with funny characters \ " " ' '
& < > > { }</ui:msg></gwt:HTML>
<demo:ClickyLink ui:field="funnyCharsAttributeWidget"
- popupText="funny characters " ' ' & < > > { }">
+ popupText="funny characters \ " ' ' & < > > {
}">
Click to see my untranslatable text passed by attribute
</demo:ClickyLink>
<br/>
<demo:ClickyLink ui:field="funnyCharsMessageAttributeWidget"
- popupText="funny characters " ' ' & < > > { }">
+ popupText="funny characters \ " ' ' & < > > {
}">
<ui:attribute name="popupText"/>
Click to see my translatable text passed by attribute
</demo:ClickyLink>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors