Skip to content

Commit

Permalink
fix regression in IsJson function (no longer accept white space in th…
Browse files Browse the repository at this point in the history
…e beginning or the end)
  • Loading branch information
michaeloffner committed Nov 16, 2023
1 parent e57dac2 commit ad3040c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ public String toSerializable(final LogEvent event) {
}

private static Object toJson(String strJson, Object defaultValue) {
if (StringUtil.isEmpty(strJson)) {
if (StringUtil.isEmpty(strJson, true)) {
return defaultValue;
}

if (!(strJson.startsWith("{") && strJson.endsWith("}") || strJson.startsWith("[") && strJson.endsWith("]"))) {
strJson = strJson.trim();
if ((!strJson.startsWith("{") && !strJson.startsWith("[")) || (!strJson.endsWith("}") && !strJson.endsWith("]"))) {
return defaultValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class IsJSON {
public static boolean call(PageContext pc, Object obj) {
String str = Caster.toString(obj, null);
if (StringUtil.isEmpty(str, true)) return false;

if (!(str.startsWith("{") && str.endsWith("}") || str.startsWith("[") && str.endsWith("]"))) {
str = str.trim();
if ((!str.startsWith("{") && !str.startsWith("[")) || (!str.endsWith("}") && !str.endsWith("]"))) {
return false;
}

Expand All @@ -41,5 +41,4 @@ public static boolean call(PageContext pc, Object obj) {
return false;
}
}

}
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="5.4.4.34-SNAPSHOT"/>
<property name="version" value="5.4.4.35-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>5.4.4.34-SNAPSHOT</version>
<version>5.4.4.35-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down
8 changes: 8 additions & 0 deletions test/functions/IsJson.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
assertFalse(isJson('{a:susi=1}'));
}

function testWhiteSpace() {
// we allow white space, even it is not really correct
assertTrue(isJson(' {a:susi=1} '));
assertTrue(isJson(' {a:susi=1} '));
assertTrue(isJson('
{a:susi=1}
'));
}

}

0 comments on commit ad3040c

Please sign in to comment.