Revision: 9981
Author:   [email protected]
Date:     Tue Apr 12 13:37:16 2011
Log:      Cherry pick r9912 and r9914 to releases/2.3 (add
CSS_ATTRIBUTE_START to HtmlTemplateParser, and fix things it
broke). Someone didn't run the smoke tests on the relase
branch, ahem.

http://code.google.com/p/google-web-toolkit/source/detail?r=9981

Modified:
/releases/2.3/user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java /releases/2.3/user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java /releases/2.3/user/src/com/google/gwt/safehtml/rebind/SafeHtmlTemplatesImplMethodCreator.java /releases/2.3/user/test/com/google/gwt/safehtml/client/SafeHtmlTemplatesTest.java /releases/2.3/user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java

=======================================
--- /releases/2.3/user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java Thu Dec 9 08:34:53 2010 +++ /releases/2.3/user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java Tue Apr 12 13:37:16 2011
@@ -74,10 +74,14 @@
* <dd>This context corresponds to a parameter that appears at the very start of * a URL-valued HTML attribute's value; in the above example this applies to
  * parameter #1.
+ * <dt>{@link HtmlContext.Type#CSS_ATTRIBUTE_START}
+ * <dd>This context corresponds to a parameter that appears at the very
+ * beginning of a {@code style} attribute's value; in the above example this
+ * applies to parameter #0.
  * <dt>{@link HtmlContext.Type#CSS_ATTRIBUTE}
* <dd>This context corresponds to a parameter that appears in the context of a
- * {@code style} attribute; in the above example this applies to
- * parameter #0.
+ * {@code style} attribute, except at the very beginning of the attribute's
+ * value.
  * <dt>{@link HtmlContext.Type#ATTRIBUTE_VALUE}
* <dd>This context corresponds to a parameter that appears within an attribute
  * and is not in one of the more specific in-attribute contexts above. In
@@ -210,7 +214,11 @@
    */
   private HtmlContext getHtmlContextFromParseState()
       throws UnableToCompleteException {
-
+ // TODO(xtof): Consider refactoring such that state related to the position
+    // of the template variable in an attribute is exposed separately (as
+ // HtmlContext#isAttributeStart(), etc). In doing so, consider trade off
+    // between combinatorial explosion of possible states vs. complexity of
+    // client code.
     if (streamHtmlParser.getState().equals(HtmlParser.STATE_ERROR)) {
       logger.log(TreeLogger.ERROR,
           "Parsing template resulted in parse error: "
@@ -250,7 +258,11 @@
       if (streamHtmlParser.isUrlStart()) {
         return new HtmlContext(HtmlContext.Type.URL_START, tag, attribute);
       } else if (streamHtmlParser.inCss()) {
- return new HtmlContext(HtmlContext.Type.CSS_ATTRIBUTE, tag, attribute);
+        if (streamHtmlParser.getValueIndex() == 0) {
+ return new HtmlContext(HtmlContext.Type.CSS_ATTRIBUTE_START, tag, attribute);
+        } else {
+ return new HtmlContext(HtmlContext.Type.CSS_ATTRIBUTE, tag, attribute);
+        }
       } else {
         return new HtmlContext(
             HtmlContext.Type.ATTRIBUTE_VALUE, tag, attribute);
=======================================
--- /releases/2.3/user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java Thu Dec 9 08:34:53 2010 +++ /releases/2.3/user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java Tue Apr 12 13:37:16 2011
@@ -64,7 +64,11 @@
       /**
        * CSS (style) attribute context.
        */
-      CSS_ATTRIBUTE
+      CSS_ATTRIBUTE,
+      /**
+       * At the very start of a CSS (style) attribute context.
+       */
+      CSS_ATTRIBUTE_START
     }

     private final Type type;
=======================================
--- /releases/2.3/user/src/com/google/gwt/safehtml/rebind/SafeHtmlTemplatesImplMethodCreator.java Tue Apr 12 08:34:05 2011 +++ /releases/2.3/user/src/com/google/gwt/safehtml/rebind/SafeHtmlTemplatesImplMethodCreator.java Tue Apr 12 13:37:16 2011
@@ -307,6 +307,7 @@
         break;

       case CSS_ATTRIBUTE:
+      case CSS_ATTRIBUTE_START:
         /*
* We already checked if the user tried to use SafeStyles in an invalid * (non-CSS_ATTRIBUTE) context, but now we check if the user could have
=======================================
--- /releases/2.3/user/test/com/google/gwt/safehtml/client/SafeHtmlTemplatesTest.java Tue Apr 12 08:34:05 2011 +++ /releases/2.3/user/test/com/google/gwt/safehtml/client/SafeHtmlTemplatesTest.java Tue Apr 12 13:37:16 2011
@@ -71,6 +71,9 @@

     @Template("<span><img src=\"{0}/{1}\"/></span>")
SafeHtml templateWithTwoPartUriAttribute(String baseUrl, String urlPart);
+
+    @Template("<span style='{0}; color: green;'></span>")
+    SafeHtml templateWithStyleAttribute(String style);
   }

   public void testSimpleTemplate() {
@@ -130,4 +133,10 @@
         templates.templateWithTwoPartUriAttribute(
             BAD_URL, "x&y").asString());
   }
-}
+
+  public void testTemplateWithStyleAttribute() {
+    Assert.assertEquals(
+        "<span style='background: purple; color: green;'></span>",
+ templates.templateWithStyleAttribute("background: purple").asString());
+  }
+}
=======================================
--- /releases/2.3/user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java Thu Dec 9 08:34:53 2010 +++ /releases/2.3/user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java Tue Apr 12 13:37:16 2011
@@ -134,10 +134,15 @@
     // Test correct detection of CSS context.
     assertParseTemplateResult(
"[L(<div class=\"), P((ATTRIBUTE_VALUE,div,class),0), L(\" style=\"), "
-            + "P((CSS_ATTRIBUTE,div,style),2), L(\">Hello ), "
+            + "P((CSS_ATTRIBUTE_START,div,style),2), L(\">Hello ), "
             + "P((TEXT,null,null),1)]",
         "<div class=\"{0}\" style=\"{2}\">Hello {1}");
     assertParseTemplateResult(
+ "[L(<div class=\"), P((ATTRIBUTE_VALUE,div,class),0), L(\" style=\"color:green; ), "
+            + "P((CSS_ATTRIBUTE,div,style),2), L(\">Hello ), "
+            + "P((TEXT,null,null),1)]",
+        "<div class=\"{0}\" style=\"color:green; {2}\">Hello {1}");
+    assertParseTemplateResult(
         "[L(<div>), P((TEXT,null,null),0), L(<style>foo ), "
             + "P((CSS,null,null),1), L(</style>)]",
         "<div>{0}<style>foo {1}</style>");

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to