Skip to content

Commit

Permalink
DROOLS-1447 Fix FEELParser.isVariableNameValid() for empty string (ki…
Browse files Browse the repository at this point in the history
  • Loading branch information
tarilabs authored and etirelli committed Feb 24, 2017
1 parent 71d32ed commit 2294111
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static FEEL_1_1Parser parse(FEELEventListenersManager eventsManager, Stri
}

public static boolean isVariableNameValid( String source ) {
if( source == null ) {
if( source == null || source.isEmpty() ) {
return false;
}
ANTLRInputStream input = new ANTLRInputStream(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.kie.dmn.core.util.DMNRuntimeUtil;
import org.kie.dmn.feel.model.v1_1.DMNModelInstrumentedBase;
import org.kie.dmn.feel.model.v1_1.Definitions;
import org.kie.dmn.feel.parser.feel11.FEELParser;
import org.kie.dmn.validation.Msg;
import org.kie.dmn.validation.ValidationMsg;
import org.kie.dmn.validation.DMNValidator;
Expand Down Expand Up @@ -378,4 +379,17 @@ public void testTYPEREF_NOT_FEEL_NOT_DEF_valid() {

assertTrue( validate.stream().noneMatch( p -> p.getMessage().equals( Msg.TYPEREF_NOT_FEEL_NOT_DEF ) ) );
}

@Test
public void testNAME_INVALID_empty_name() {
assertFalse( FEELParser.isVariableNameValid(null) );

// DROOLS-1447
assertFalse( FEELParser.isVariableNameValid("") );

Definitions definitions = utilDefinitions( "DROOLS-1447.dmn", "DROOLS-1447" );
List<ValidationMsg> validate = validator.validateModel(definitions);

assertTrue( validate.stream().anyMatch( p -> p.getMessage().equals( Msg.NAME_INVALID ) ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<definitions id="DROOLS-1447" name="DROOLS-1447"
namespace="https://github.com/droolsjbpm/kie-dmn" xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.omg.org/spec/DMN/20151101/dmn.xsd http://www.omg.org/spec/DMN/20151101/dmn.xsd ">
<extensionElements />
<decision id="_c7523fa1-22af-4673-8990-fdf920b35667" name="Decision Logic 1">
<variable id="_b1e4588e-9ce1-4474-8e4e-48dbcdb7524b" name="Decision Logic 1" />
</decision>
<decision id="_5e43b55c-888e-443c-b1b9-80e4aa6746bd" name="">
<variable id="_cd52910c-65e5-448d-8e60-1912b5db849e" name="" />
</decision>
</definitions>

0 comments on commit 2294111

Please sign in to comment.