Skip to content

Commit

Permalink
LDEV-5024 - add option to allow empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jul 16, 2024
1 parent a5318fc commit b5f42c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import java.util.Iterator;

import lucee.commons.io.SystemUtil;
import lucee.commons.io.log.Log;
import lucee.commons.io.log.LogUtil;
import lucee.commons.lang.StringUtil;
import lucee.runtime.PageContext;
import lucee.runtime.exp.FunctionException;
Expand All @@ -45,15 +48,26 @@
public final class DeserializeJSON extends BIF implements Function {

private static final long serialVersionUID = -4847186239512149277L;
private static final boolean allowEmpty;
static {
allowEmpty = Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.deserializejson.allowempty", null), false);
}

private static final Key ROWCOUNT = KeyConstants._ROWCOUNT;

public static Object call(PageContext pc, String JSONVar) throws PageException {
return call(pc, JSONVar, true);
}

public static Object call(PageContext pc, String JSONVar, boolean strictMapping) throws PageException {
if (StringUtil.isEmpty(JSONVar, true))
if (StringUtil.isEmpty(JSONVar, true)) {
if (allowEmpty) {
LogUtil.log(Log.LEVEL_WARN, "datasource", "conversion",
"Deprecated functionality used at [" + LogUtil.caller(pc, "") + "]. An empty string was passed as a value to the function DeserializeJSON.");
return "";
}
throw new FunctionException(pc, "DeserializeJSON", 1, "JSONVar", "input value cannot be empty string.", "Must be the valid JSON string");
}
Object result = new JSONExpressionInterpreter().interpret(pc, JSONVar);
if (!strictMapping) return toQuery(result);
return result;
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.1.0.241-RC"/>
<property name="version" value="6.1.0.242-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.1.0.241-RC</version>
<version>6.1.0.242-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit b5f42c7

Please sign in to comment.