Revision: 10636
Author:   rj...@google.com
Date:     Thu Sep  8 10:49:11 2011
Log: Fix http://code.google.com/p/google-web-toolkit/issues/detail?id=6161
by dying on suspicious looking namespaces. Also keep
StackLayoutPanelParser from generating bad code for such things.

Review at http://gwt-code-reviews.appspot.com/1520807

Review by: mros...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10636

Modified:
 /trunk/user/src/com/google/gwt/uibinder/elementparsers/HtmlInterpreter.java
/trunk/user/src/com/google/gwt/uibinder/elementparsers/StackPanelParser.java
 /trunk/user/src/com/google/gwt/uibinder/rebind/XMLElement.java
/trunk/user/test/com/google/gwt/uibinder/elementparsers/StackPanelParserTest.java /trunk/user/test/com/google/gwt/uibinder/rebind/UiBinderParserUiWithTest.java

=======================================
--- /trunk/user/src/com/google/gwt/uibinder/elementparsers/HtmlInterpreter.java Thu Aug 18 06:20:28 2011 +++ /trunk/user/src/com/google/gwt/uibinder/elementparsers/HtmlInterpreter.java Thu Sep 8 10:49:11 2011
@@ -130,6 +130,12 @@
     if (writer.isImportedElement(elem)) {
       writer.die(elem, "Not allowed in an HTML context");
     }
+
+    if (elem.getNamespaceUri() != null && !writer.isBinderElement(elem)) {
+      // It's not a widget, and it's not a ui: element.
+ writer.die(elem, "Prefix \"%s:\" has unrecognized xmlns \"%s\" (bad import?)",
+        elem.getPrefix(), elem.getNamespaceUri());
+    }

     return pipe.interpretElement(elem);
   }
=======================================
--- /trunk/user/src/com/google/gwt/uibinder/elementparsers/StackPanelParser.java Thu May 5 09:42:56 2011 +++ /trunk/user/src/com/google/gwt/uibinder/elementparsers/StackPanelParser.java Thu Sep 8 10:49:11 2011
@@ -31,7 +31,10 @@
       UiBinderWriter writer) throws UnableToCompleteException {
     // Parse children.
     for (XMLElement child : elem.consumeChildElements()) {
-
+      if (!writer.isWidgetElement(child)) {
+        writer.die(child, "Widget required");
+      }
+
// Stack panel label comes from the StackPanel-text attribute of the child
       String stackItemLabel = null;
String variableAttributeName = elem.getPrefix() + ":" + ATTRIBUTE_TEXT;
=======================================
--- /trunk/user/src/com/google/gwt/uibinder/rebind/XMLElement.java Thu Aug 18 06:20:28 2011 +++ /trunk/user/src/com/google/gwt/uibinder/rebind/XMLElement.java Thu Sep 8 10:49:11 2011
@@ -773,11 +773,6 @@
   public String getNamespaceUri() {
     return elem.getNamespaceURI();
   }
-
-  public String getNamespaceUriForAttribute(String fieldName) {
-    Attr attr = elem.getAttributeNode(fieldName);
-    return attr.getNamespaceURI();
-  }

   /**
* Returns the parent element, or null if parent is null or a node type other
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/elementparsers/StackPanelParserTest.java Tue Aug 31 08:46:42 2010 +++ /trunk/user/test/com/google/gwt/uibinder/elementparsers/StackPanelParserTest.java Thu Sep 8 10:49:11 2011
@@ -15,8 +15,12 @@
  */
 package com.google.gwt.uibinder.elementparsers;

+import com.google.gwt.core.ext.UnableToCompleteException;
+
 import junit.framework.TestCase;

+import org.xml.sax.SAXParseException;
+
 import java.util.Iterator;

 /**
@@ -34,7 +38,7 @@
     tester = new ElementParserTester(PARSED_TYPE, new StackPanelParser());
   }

-  public void testHappy_noStackText() throws Exception {
+ public void testHappy_noStackText() throws SAXParseException, UnableToCompleteException {
     StringBuffer b = new StringBuffer();
     b.append("<g:StackPanel>");
     b.append("  <g:Button/>");
@@ -45,7 +49,7 @@
     assertStatements("fieldName.add(<g:Button>);");
   }

-  public void testHappy_hasStackText() throws Exception {
+ public void testHappy_hasStackText() throws SAXParseException, UnableToCompleteException {
     StringBuffer b = new StringBuffer();
     b.append("<g:StackPanel>");
     b.append("  <g:Button g:StackPanel-text='Foo'/>");
@@ -55,6 +59,19 @@

     assertStatements("fieldName.add(<g:Button>, \"Foo\");");
   }
+
+  public void testBadChild() throws SAXParseException {
+    StringBuffer b = new StringBuffer();
+    b.append("<g:StackPanel>");
+    b.append("  <g:UIObject/>");
+    b.append("</g:StackPanel>");
+    try {
+      tester.parse(b.toString());
+      fail("Expected UnableToCompleteException");
+    } catch (UnableToCompleteException e) {
+      /* pass */
+    }
+  }

   private void assertStatements(String... expected) {
     Iterator<String> i = tester.writer.statements.iterator();
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/rebind/UiBinderParserUiWithTest.java Wed Sep 7 09:32:44 2011 +++ /trunk/user/test/com/google/gwt/uibinder/rebind/UiBinderParserUiWithTest.java Thu Sep 8 10:49:11 2011
@@ -141,7 +141,6 @@

   private UiBinderWriter writer;

-  @SuppressWarnings("deprecation")
   @Override
   public void setUp() throws Exception {
     super.setUp();

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

Reply via email to