Skip to content

Commit 1d033a8

Browse files
committed
safe down cast
1 parent 5bf33c4 commit 1d033a8

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/server/services/wfs3/qgswfs3handlers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,14 +675,14 @@ void QgsWfs3AbstractItemsHandler::gatherLayerFieldsInfo( json &data, const QgsVe
675675
const QgsExpression expression( constraints.constraintExpression() );
676676
if ( expression.isValid() && expression.rootNode()->dump().startsWith( "regexp_match("_L1 ) )
677677
{
678-
if ( const QgsExpressionNodeFunction *functionNode = qgis::down_cast<const QgsExpressionNodeFunction *>( expression.rootNode() ) )
678+
if ( const QgsExpressionNodeFunction *functionNode = dynamic_cast<const QgsExpressionNodeFunction *>( expression.rootNode() ) )
679679
{
680680
QgsExpressionNode::NodeList *functionArgs = functionNode->args();
681681
if ( functionArgs->count() == 2 )
682682
{
683-
if ( const QgsExpressionNodeColumnRef *columnNode = qgis::down_cast<const QgsExpressionNodeColumnRef *>( functionArgs->at( 0 ) ); columnNode->name() == field.name() )
683+
if ( const QgsExpressionNodeColumnRef *columnNode = dynamic_cast<const QgsExpressionNodeColumnRef *>( functionArgs->at( 0 ) ); columnNode->name() == field.name() )
684684
{
685-
if ( const QgsExpressionNodeLiteral *patternNode = qgis::down_cast<const QgsExpressionNodeLiteral *>( functionArgs->at( 1 ) ) )
685+
if ( const QgsExpressionNodeLiteral *patternNode = dynamic_cast<const QgsExpressionNodeLiteral *>( functionArgs->at( 1 ) ) )
686686
{
687687
fInfo.pattern = patternNode->value().toString().toStdString();
688688
}

tests/src/python/test_qgsserver_ogcapi_schema.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,36 @@ def _test_widget_conf(
253253
expression="regexp_match(\"field1\", '^[A-Z]{3}$')",
254254
)
255255

256+
# Field with regexp expression constraint but on another field - should not be picked up as a pattern constraint
257+
field = QgsField("field1", QtCore.QMetaType.Type.QString)
258+
_test_widget_conf(
259+
field,
260+
"TextEdit",
261+
{},
262+
{
263+
"type": "string",
264+
"readOnly": True,
265+
"x-ogc-propertySeq": 2,
266+
},
267+
read_only=True,
268+
expression="regexp_match(\"field2\", '^[A-Z]{3}$')",
269+
)
270+
271+
# Field with regexp expression constraint but taken from another field - should not be picked up as a pattern constraint
272+
field = QgsField("field1", QtCore.QMetaType.Type.QString)
273+
_test_widget_conf(
274+
field,
275+
"TextEdit",
276+
{},
277+
{
278+
"type": "string",
279+
"readOnly": True,
280+
"x-ogc-propertySeq": 2,
281+
},
282+
read_only=True,
283+
expression='regexp_match("field1", "refield")',
284+
)
285+
256286
# ValueMap
257287
_test_widget_conf(
258288
QgsField("field1", QtCore.QMetaType.Type.QString),

0 commit comments

Comments
 (0)