From: Manuel Carrasco MoƱino Date: Fri, 22 Feb 2013 10:50:47 +0000 (+0100) Subject: Fix edge case when properties string ends with coma X-Git-Tag: release-1.3.2~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c36e403dc90a0d0e4fb4ce40ad225acc3db7da7d;p=gwtquery.git Fix edge case when properties string ends with coma --- 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 cc8d6b3f..8e68b184 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 @@ -48,7 +48,7 @@ public class Properties extends JavaScriptObject { .replaceAll("\\s+([:\\)\\(,;}{'\"])" , "$1") // Remove spaces .replaceFirst("^[\\(]+(.*)[\\)]+$", "$1") // Remove () .replaceAll("\\([\"']([^\\)]+)[\"']\\)" , "($1)") // Remove quotes - .replaceAll("[;,]+([\\w-\\$]+):", ";$1:") // Change comma by semicolon + .replaceAll("[;,]+([\\w-\\$]+:|$)", ";$1") // Change comma by semicolon .replaceAll("([^,;])([\\]}])", "$1;$2") // Put control semicolon used below .replaceAll(":\\s*[\"']?([^;\\{\\}\\[\\]\"']*)[\"']?\\s*([;,]+|$)", ":\"$1\";") // put quotes to all values (even empty) .replaceAll("[;,]+([\\w-]+):", ";$1:") // Change semicolon by comma @@ -61,6 +61,7 @@ public class Properties extends JavaScriptObject { .replaceAll("[;,]+([\\]\\}]|$)", "$1") // remove endings ; ret = ret.matches("(^[\\[\\{].*[\\]\\}]$)") ? ret : "{" + ret + "}"; + System.out.println(s + " -> " + ret); return ret; } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java index af755243..e92654f7 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java @@ -47,7 +47,7 @@ public class JreQueryCoreTest extends GWTTestCase { assertEquals("{\"width\":\"\",\"top\":\"\"}", Properties .wrapPropertiesString("width: '' ; top:'' ;")); assertEquals("{\"border-left\":\"solid\"}", Properties - .wrapPropertiesString("border-left: solid")); + .wrapPropertiesString("border-left: solid,")); assertEquals("[{\"a\":1,\"b\":{\"a\":2,\"b\":{\"a\":3}},\"u\":\"url\",\"d\":2,\"t\":[\"hola\",\"adios\"],\"z\":true}]", Properties .wrapPropertiesString("[{a:1, b:{a:2,b:{a:3}},u:url, d:'2','t':['hola','adios'], 'z': true}]")); assertEquals("{\"$x\":22.60,\"$y\":\".0\",\"h\":\"#y\"}", Properties