Skip to content

Commit 74ca3db

Browse files
committed
fix(validation): validate table function arguments
SelectValidator only checked that table functions are allowed and never validated the functions themselves, so features, names and nested queries in their arguments went unchecked. This covers both f(..) and every function of ROWS FROM (..).
1 parent 8a11ae3 commit 74ca3db

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/main/java/net/sf/jsqlparser/util/validation/validator/SelectValidator.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ public <S> Void visit(TableStatement tableStatement, S context) {
464464
@Override
465465
public <S> Void visit(TableFunction tableFunction, S context) {
466466
validateFeature(Feature.tableFunction);
467+
validateOptionalExpressions(tableFunction.getFunctions());
467468

468469
validateOptional(tableFunction.getPivot(), p -> p.accept(this, context));
469470
validateOptional(tableFunction.getUnPivot(), up -> up.accept(this, context));

‎src/test/java/net/sf/jsqlparser/util/validation/validator/SelectValidatorTest.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import net.sf.jsqlparser.util.validation.feature.FeaturesAllowed;
1818
import net.sf.jsqlparser.util.validation.feature.MariaDbVersion;
1919
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.params.ParameterizedTest;
21+
import org.junit.jupiter.params.provider.ValueSource;
2022

2123
public class SelectValidatorTest extends ValidationTestAsserts {
2224

@@ -206,6 +208,28 @@ public void testValidateTableFunction() {
206208
}
207209
}
208210

211+
/**
212+
* {@link FeaturesAllowed#SELECT} does not allow {@link Feature#jdbcParameter}, so a {@code ?}
213+
* argument must be reported wherever the function is written.
214+
*/
215+
private static final FeaturesAllowed SELECT_WITH_TABLE_FUNCTIONS =
216+
new FeaturesAllowed("SELECT + tableFunction", Feature.tableFunction)
217+
.add(FeaturesAllowed.SELECT);
218+
219+
@Test
220+
public void testValidateFunctionArgumentInWhere() {
221+
validateNotAllowed("SELECT * FROM t WHERE a = f(?)", 1, 1, SELECT_WITH_TABLE_FUNCTIONS,
222+
Feature.jdbcParameter);
223+
}
224+
225+
@ParameterizedTest
226+
@ValueSource(strings = {"SELECT * FROM f(?)",
227+
"SELECT * FROM ROWS FROM (f(1), g(?))",
228+
"SELECT * FROM ROWS FROM (f(1), g(?)) WITH ORDINALITY"})
229+
public void testValidateTableFunctionArguments(String sql) {
230+
validateNotAllowed(sql, 1, 1, SELECT_WITH_TABLE_FUNCTIONS, Feature.jdbcParameter);
231+
}
232+
209233
@Test
210234
public void testValidateLateral() throws JSQLParserException {
211235
validateNoErrors(

0 commit comments

Comments
 (0)