Skip to content

Commit bfde7c8

Browse files
committedMar 18, 2013
Filter string in qgis server: Allow strings and attribute names with spaces
1 parent 9a81fa7 commit bfde7c8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
 

‎src/mapserver/qgswmsserver.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,9 @@ bool QgsWMSServer::testFilterStringSafety( const QString& filter ) const
18621862
}
18631863

18641864
QStringList tokens = filter.split( " ", QString::SkipEmptyParts );
1865+
groupStringList( tokens, "'" );
1866+
groupStringList( tokens, "\"" );
1867+
18651868
QStringList::const_iterator tokenIt = tokens.constBegin();
18661869
for ( ; tokenIt != tokens.constEnd(); ++tokenIt )
18671870
{
@@ -1926,6 +1929,55 @@ bool QgsWMSServer::testFilterStringSafety( const QString& filter ) const
19261929
return true;
19271930
}
19281931

1932+
void QgsWMSServer::groupStringList( QStringList& list, const QString& groupString )
1933+
{
1934+
//group contens within single quotes together
1935+
bool groupActive = false;
1936+
int startGroup = -1;
1937+
int endGroup = -1;
1938+
QString concatString;
1939+
1940+
for ( int i = 0; i < list.size(); ++i )
1941+
{
1942+
QString& str = list[i];
1943+
if ( str.startsWith( groupString ) )
1944+
{
1945+
startGroup = i;
1946+
groupActive = true;
1947+
concatString.clear();
1948+
}
1949+
1950+
if ( groupActive )
1951+
{
1952+
if ( i != startGroup )
1953+
{
1954+
concatString.append( " " );
1955+
}
1956+
concatString.append( str );
1957+
}
1958+
1959+
if ( str.endsWith( groupString ) )
1960+
{
1961+
endGroup = i;
1962+
groupActive = false;
1963+
1964+
if ( startGroup != -1 )
1965+
{
1966+
list[startGroup] = concatString;
1967+
for ( int j = startGroup + 1; j <= endGroup; ++j )
1968+
{
1969+
list.removeAt( j );
1970+
--i;
1971+
}
1972+
}
1973+
1974+
concatString.clear();
1975+
startGroup = -1;
1976+
endGroup = -1;
1977+
}
1978+
}
1979+
}
1980+
19291981
QStringList QgsWMSServer::applyFeatureSelections( const QStringList& layerList ) const
19301982
{
19311983
QStringList layersWithSelections;

‎src/mapserver/qgswmsserver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class QgsWMSServer
160160
/**Tests if a filter sql string is allowed (safe)
161161
@return true in case of success, false if string seems unsafe*/
162162
bool testFilterStringSafety( const QString& filter ) const;
163+
/**Helper function for filter safety test. Groups stringlist to merge entries starting/ending with quotes*/
164+
static void groupStringList( QStringList& list, const QString& groupString );
163165

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

0 commit comments

Comments
 (0)
Please sign in to comment.