Skip to content
Permalink
Browse files
Filter string in qgis server: Allow strings and attribute names with …
…spaces
  • Loading branch information
mhugent committed Mar 18, 2013
1 parent 9a81fa7 commit bfde7c834a73280d05a9c7495a44c5563b7b70cd
Showing with 54 additions and 0 deletions.
  1. +52 −0 src/mapserver/qgswmsserver.cpp
  2. +2 −0 src/mapserver/qgswmsserver.h
@@ -1862,6 +1862,9 @@ bool QgsWMSServer::testFilterStringSafety( const QString& filter ) const
}

QStringList tokens = filter.split( " ", QString::SkipEmptyParts );
groupStringList( tokens, "'" );
groupStringList( tokens, "\"" );

QStringList::const_iterator tokenIt = tokens.constBegin();
for ( ; tokenIt != tokens.constEnd(); ++tokenIt )
{
@@ -1926,6 +1929,55 @@ bool QgsWMSServer::testFilterStringSafety( const QString& filter ) const
return true;
}

void QgsWMSServer::groupStringList( QStringList& list, const QString& groupString )
{
//group contens within single quotes together
bool groupActive = false;
int startGroup = -1;
int endGroup = -1;
QString concatString;

for ( int i = 0; i < list.size(); ++i )
{
QString& str = list[i];
if ( str.startsWith( groupString ) )
{
startGroup = i;
groupActive = true;
concatString.clear();
}

if ( groupActive )
{
if ( i != startGroup )
{
concatString.append( " " );
}
concatString.append( str );
}

if ( str.endsWith( groupString ) )
{
endGroup = i;
groupActive = false;

if ( startGroup != -1 )
{
list[startGroup] = concatString;
for ( int j = startGroup + 1; j <= endGroup; ++j )
{
list.removeAt( j );
--i;
}
}

concatString.clear();
startGroup = -1;
endGroup = -1;
}
}
}

QStringList QgsWMSServer::applyFeatureSelections( const QStringList& layerList ) const
{
QStringList layersWithSelections;
@@ -160,6 +160,8 @@ class QgsWMSServer
/**Tests if a filter sql string is allowed (safe)
@return true in case of success, false if string seems unsafe*/
bool testFilterStringSafety( const QString& filter ) const;
/**Helper function for filter safety test. Groups stringlist to merge entries starting/ending with quotes*/
static void groupStringList( QStringList& list, const QString& groupString );

/**Select vector features with ids specified in parameter SELECTED, e.g. ...&SELECTED=layer1:1,2,9;layer2:3,5,10&...
@return list with layer ids where selections have been created*/

0 comments on commit bfde7c8

Please sign in to comment.