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 84a7830 commit 352ee81
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 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,6 +28,12 @@ public class IsJSON {
public static boolean call(PageContext pc, Object obj) {
String str = Caster.toString(obj, null);
if (StringUtil.isEmpty(str, true)) return false;

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

try {
new JSONExpressionInterpreter().interpret(pc, str);
return true;
Expand Down
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="6.0.1.27-SNAPSHOT"/>
<property name="version" value="6.0.1.28-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>6.0.1.27-SNAPSHOT</version>
<version>6.0.1.28-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down
9 changes: 8 additions & 1 deletion test/functions/IsJson.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,12 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
assertTrue(isJson('{}'));
assertEquals(deserializeJson('{}'), {});
}

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

0 comments on commit 352ee81

Please sign in to comment.