]> source.dussan.org Git - gwtquery.git/commitdiff
Fix edge case when properties string ends with coma
authorManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Fri, 22 Feb 2013 10:50:47 +0000 (11:50 +0100)
committerManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Fri, 22 Feb 2013 10:50:47 +0000 (11:50 +0100)
gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java
gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java

index cc8d6b3f04ad1a3baf715b3ec9fd5c1e2817f2c4..8e68b184e5e73ab0da3560d2ffdeff03009de4dd 100644 (file)
@@ -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;
   }
 
index af755243d23aa0688cced13d8214fb194b85eacd..e92654f7ae7c86c6e2a8c3dc8cf7f3450240b538 100644 (file)
@@ -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