Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDEV-4645 bugfix for cfprocparam and empty char strings #2186

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/main/java/lucee/runtime/tag/ProcParamBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ public Object getValueForCF() throws PageException {
@Override
public boolean isNulls() {
return getValue() == null
|| (sqlType != Types.VARCHAR && sqlType != Types.LONGVARCHAR && sqlType != Types.NVARCHAR && getValue() instanceof String && StringUtil.isEmpty(getValue()));
|| (sqlType != Types.VARCHAR && sqlType != Types.LONGVARCHAR && sqlType != Types.NVARCHAR
&& sqlType != Types.NCHAR && sqlType != Types.CHAR
&& getValue() instanceof String && StringUtil.isEmpty(getValue()));
}

@Override
Expand Down
42 changes: 40 additions & 2 deletions test/tickets/LDEV1917.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,48 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="mysql" {
}
function run( testResults , testBox ) {
if(!hasCredentials()) return;
describe( "test suite for LDEV-1917()", function() {
describe( "test suite for LDEV-1917", function() {
it(title = "cfprocparam passes null instead of empty strings with NVARCHAR cfsqltype", body = function( currentSpec ) {
local.result = _InternalRequest(
template:"#variables.uri#/test.cfm"
template:"#variables.uri#/test.cfm",
form: {
datatype: "nvarchar"
}
);
expect(local.result.filecontent.trim()).toBeTrue();
});

it(title = "cfprocparam passes null instead of empty strings with CHAR cfsqltype", body = function( currentSpec ) {
local.result = _InternalRequest(
template:"#variables.uri#/test.cfm",
form: {
datatype: "char"
}
);
expect(local.result.filecontent.trim()).toBeTrue();
});
});

describe( "test suite for LDEV-4645", function() {

it(title = "cfprocparam passes null instead of empty strings with NVARCHAR cfsqltype, col not null", body = function( currentSpec ) {
local.result = _InternalRequest(
template:"#variables.uri#/test.cfm",
form: {
datatype: "nvarchar",
notNull: true
}
);
expect(local.result.filecontent.trim()).toBeTrue();
});

it(title = "cfprocparam passes null instead of empty strings with CHAR cfsqltype, col not null", body = function( currentSpec ) {
local.result = _InternalRequest(
template:"#variables.uri#/test.cfm",
form: {
datatype: "char",
notNull: true
}
);
expect(local.result.filecontent.trim()).toBeTrue();
});
Expand Down
17 changes: 12 additions & 5 deletions test/tickets/LDEV1917/Application.cfc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
component {
this.name = "ac";
this.name = "ldev-1917";

param name="form.datatype";
param name="form.notNull" default="false";


if (form.datatype neq "char" and form.datatype neq "nvarchar")
throw "bad datatype [#form.datatype#]";

mySQL = getCredentials();
if(mySQL.count()!=0){
Expand All @@ -8,21 +15,21 @@ component {

public function onRequestStart() {
setting requesttimeout=10;
}

public function onApplicationStart() {
var extra= form.notNull ? " NOT NULL" : "";

query {
echo("DROP PROCEDURE IF EXISTS `LDEV1917SP`");
}
query {
echo("DROP TABLE IF EXISTS `LDEV1917`");
}
query {
echo("CREATE TABLE LDEV1917 (null_Value nvarchar(10))");
echo("CREATE TABLE LDEV1917 (null_Value #form.datatype#(10) #extra# )");
}
query {
echo("
CREATE PROCEDURE `LDEV1917SP`(IN null_Value nvarchar(10))
CREATE PROCEDURE `LDEV1917SP`(IN null_Value #form.datatype#(10))
BEGIN
INSERT INTO LDEV1917 VALUE(null_Value);
END
Expand Down
2 changes: 1 addition & 1 deletion test/tickets/LDEV1917/test.cfm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<cfstoredproc procedure="LDEV1917SP">
<cfprocparam type = "IN" CFSQLType = "NVARCHAR" value = "" null=false>
<cfprocparam type = "IN" CFSQLType = "#form.datatype#" value = "" null=false>
</cfstoredproc>
<cfquery name="test1917">
select * from LDEV1917
Expand Down