Skip to content
Permalink
Browse files
check for valid field index in QgsFieldFormatter::representValue
  • Loading branch information
troopa81 authored and nyalldawson committed Nov 1, 2021
1 parent fe4dbff commit 98cd09e952f9b44c2b7f6c7e315c307b818fc305
Showing with 5 additions and 0 deletions.
  1. +3 −0 src/core/qgsfieldformatter.cpp
  2. +2 −0 tests/src/python/test_qgsfieldformatters.py
@@ -26,6 +26,9 @@ QString QgsFieldFormatter::representValue( QgsVectorLayer *layer, int fieldIndex
Q_UNUSED( config )
Q_UNUSED( cache )

if ( ! layer->fields().exists( fieldIndex ) )
return QString();

QString defVal;
if ( layer->fields().fieldOrigin( fieldIndex ) == QgsFields::OriginProvider && layer->dataProvider() )
defVal = layer->dataProvider()->defaultValueClause( layer->fields().fieldOriginIndex( fieldIndex ) );
@@ -633,6 +633,8 @@ def test_representValueWithDefault(self):
'4')
self.assertEqual(fieldFormatter.representValue(vl, 1, {}, None, "123"),
'123')
# bad field index
self.assertEqual(fieldFormatter.representValue(vl, 3, {}, None, 5), "")


if __name__ == '__main__':

0 comments on commit 98cd09e

Please sign in to comment.