]> source.dussan.org Git - gwtquery.git/commitdiff
Does not die when properties syntax is wrong
authorManolo Carrasco <manolo@apache.org>
Wed, 23 Feb 2011 09:30:48 +0000 (09:30 +0000)
committerManolo Carrasco <manolo@apache.org>
Wed, 23 Feb 2011 09:30:48 +0000 (09:30 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java

index 178deabb44053063de139219f4f7468d96b04193..9c5f3a90f300ef60624b00f7a7a53f15b2f4cd24 100644 (file)
@@ -26,15 +26,24 @@ import com.google.gwt.core.client.JsArrayString;
 public class Properties extends JavaScriptObject {\r
   \r
   public static Properties create(String properties) {\r
-    return (Properties) createImpl(wrapPropertiesString(properties));\r
+    String p = wrapPropertiesString(properties);\r
+    try {\r
+      return (Properties) createImpl(p);\r
+    } catch (Exception e) {\r
+      System.err.println("Error creating Properties: \n" + properties  + "\n" + p + "\n" + e.getMessage());\r
+      return (Properties) createImpl("({})");\r
+    }\r
   }\r
 \r
   public static final native JavaScriptObject createImpl(String properties) /*-{\r
-      return eval(properties);\r
-    }-*/;\r
+     return eval(properties);\r
+  }-*/;\r
 \r
-  protected static String wrapPropertiesString(String s) {\r
-    return "({" + s.replaceFirst("^[({]+", "").replaceFirst("[})]+$", "") + "})";\r
+  public static String wrapPropertiesString(String s) {\r
+    String ret = "({"\r
+        + s.replaceFirst("^[({]+", "").replaceFirst("[})]+$", "")\r
+        .replaceAll(":\\s*([^\"'\\s])([^,}]+)\\s*", ":\"$1$2\"") + "})";\r
+    return ret;\r
   }\r
 \r
   protected Properties() {\r
@@ -99,6 +108,6 @@ public class Properties extends JavaScriptObject {
     for (String k : keys()){\r
       ret += k + ": '" + get(k) + "', ";\r
     }\r
-    return "({" + ret.replaceAll("[, ]+","") + "})";\r
+    return "({" + ret.replaceAll("[, ]+$","") + "})";\r
   }\r
 }\r