From: Manolo Carrasco Date: Wed, 23 Feb 2011 09:30:48 +0000 (+0000) Subject: Does not die when properties syntax is wrong X-Git-Tag: release-1.3.2~527 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=742e3c11e31bf4db429a13810a390a3c6e2c99b4;p=gwtquery.git Does not die when properties syntax is wrong --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java index 178deabb..9c5f3a90 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java @@ -26,15 +26,24 @@ import com.google.gwt.core.client.JsArrayString; public class Properties extends JavaScriptObject { public static Properties create(String properties) { - return (Properties) createImpl(wrapPropertiesString(properties)); + String p = wrapPropertiesString(properties); + try { + return (Properties) createImpl(p); + } catch (Exception e) { + System.err.println("Error creating Properties: \n" + properties + "\n" + p + "\n" + e.getMessage()); + return (Properties) createImpl("({})"); + } } public static final native JavaScriptObject createImpl(String properties) /*-{ - return eval(properties); - }-*/; + return eval(properties); + }-*/; - protected static String wrapPropertiesString(String s) { - return "({" + s.replaceFirst("^[({]+", "").replaceFirst("[})]+$", "") + "})"; + public static String wrapPropertiesString(String s) { + String ret = "({" + + s.replaceFirst("^[({]+", "").replaceFirst("[})]+$", "") + .replaceAll(":\\s*([^\"'\\s])([^,}]+)\\s*", ":\"$1$2\"") + "})"; + return ret; } protected Properties() { @@ -99,6 +108,6 @@ public class Properties extends JavaScriptObject { for (String k : keys()){ ret += k + ": '" + get(k) + "', "; } - return "({" + ret.replaceAll("[, ]+","") + "})"; + return "({" + ret.replaceAll("[, ]+$","") + "})"; } }