Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Filter string in qgis server: Allow strings and attribute names with …
…spaces
  • Loading branch information
mhugent committed Mar 18, 2013
1 parent 9a81fa7 commit bfde7c8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgswmsserver.h
Expand Up @@ -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*/
Expand Down

0 comments on commit bfde7c8

Please sign in to comment.