Skip to content

Commit ff17645

Browse files
committedApr 4, 2016
Merge pull request #2963 from elpaso/server-fix-qs-encoding
[SERVER] Fix encoding of query string for bindings
2 parents 5414637 + 5a72bc7 commit ff17645

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed
 

‎src/server/qgsserver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ bool QgsServer::init( int & argc, char ** argv )
441441
void QgsServer::putenv( const QString &var, const QString &val )
442442
{
443443
#ifdef _MSC_VER
444-
_putenv_s( var.toUtf8().data(), val.toUtf8().data() );
444+
_putenv_s( var.toStdString().c_str(), val.toStdString().c_str() );
445445
#else
446-
setenv( var.toUtf8().data(), val.toUtf8().data(), 1 );
446+
setenv( var.toStdString().c_str(), val.toStdString().c_str(), 1 );
447447
#endif
448448
}
449449

‎tests/src/python/test_qgsserver.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ def setUp(self):
4141
pass
4242
self.server = QgsServer()
4343

44+
def assert_headers(self, header, body):
45+
headers = Message(StringIO(header))
46+
if 'content-length' in headers:
47+
content_length = int(headers['content-length'])
48+
body_length = len(body)
49+
self.assertEqual(content_length, body_length, msg="Header reported content-length: %d Actual body length was: %d" % (content_length, body_length))
50+
4451
def test_destructor_segfaults(self):
4552
"""Segfault on destructor?"""
4653
server = QgsServer()
@@ -294,20 +301,29 @@ def test_getfeature(self):
294301
for id, req in tests:
295302
self.wfs_getfeature_compare(id, req)
296303

297-
def assert_headers(self, header, body):
298-
headers = Message(StringIO(header))
299-
if 'content-length' in headers:
300-
content_length = int(headers['content-length'])
301-
body_length = len(body)
302-
self.assertEqual(content_length, body_length, msg="Header reported content-length: %d Actual body length was: %d" % (content_length, body_length))
304+
def test_getLegendGraphics(self):
305+
"""Test that does not return an exception but an image"""
306+
parms = {
307+
'MAP': self.testdata_path + "test%2Bproject.qgs",
308+
'SERVICE': 'WMS',
309+
'VERSIONE': '1.0.0',
310+
'REQUEST': 'GetLegendGraphic',
311+
'FORMAT': 'image/png',
312+
#'WIDTH': '20', # optional
313+
#'HEIGHT': '20', # optional
314+
'LAYER': u'testlayer+èé',
315+
}
316+
qs = '&'.join([u"%s=%s" % (k, v) for k, v in parms.iteritems()])
317+
h, r = self.server.handleRequest(qs)
318+
self.assertEquals(-1, h.find('Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
319+
self.assertNotEquals(-1, h.find('Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))
320+
303321

304322
# The following code was used to test type conversion in python bindings
305323
# def test_qpair(self):
306324
# """Test QPair bindings"""
307325
# f, s = self.server.testQPair(('First', 'Second'))
308326
# self.assertEqual(f, 'First')
309327
# self.assertEqual(s, 'Second')
310-
311-
312328
if __name__ == '__main__':
313329
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.