From c36e403dc90a0d0e4fb4ce40ad225acc3db7da7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Fri, 22 Feb 2013 11:50:47 +0100 Subject: [PATCH] Fix edge case when properties string ends with coma --- .../src/main/java/com/google/gwt/query/client/Properties.java | 3 ++- .../java/com/google/gwt/query/client/JreQueryCoreTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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 -- 2.39.5