mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
[processing] Fix escaping of srcnodata argument in Build Virtual Raster
alg
This commit is contained in:
parent
33b0dbe761
commit
c5dd8714a8
@ -255,7 +255,8 @@ class GdalUtils:
|
|||||||
for s in strList:
|
for s in strList:
|
||||||
if not isinstance(s, str):
|
if not isinstance(s, str):
|
||||||
s = str(s)
|
s = str(s)
|
||||||
if s and s[0] != '-' and any(c in s for c in escChars):
|
# don't escape if command starts with - and isn't a negative number, e.g. -9999
|
||||||
|
if s and re.match(r'^([^-]|-\d)', s) and any(c in s for c in escChars):
|
||||||
escaped = '"' + s.replace('\\', '\\\\').replace('"', '"""') \
|
escaped = '"' + s.replace('\\', '\\\\').replace('"', '"""') \
|
||||||
+ '"'
|
+ '"'
|
||||||
else:
|
else:
|
||||||
|
@ -196,7 +196,8 @@ class buildvrt(GdalAlgorithm):
|
|||||||
|
|
||||||
if self.SRC_NODATA in parameters and parameters[self.SRC_NODATA] not in (None, ''):
|
if self.SRC_NODATA in parameters and parameters[self.SRC_NODATA] not in (None, ''):
|
||||||
nodata = self.parameterAsString(parameters, self.SRC_NODATA, context)
|
nodata = self.parameterAsString(parameters, self.SRC_NODATA, context)
|
||||||
arguments.append('-srcnodata "{}"'.format(nodata))
|
arguments.append('-srcnodata')
|
||||||
|
arguments.append(nodata)
|
||||||
|
|
||||||
if self.EXTRA in parameters and parameters[self.EXTRA] not in (None, ''):
|
if self.EXTRA in parameters and parameters[self.EXTRA] not in (None, ''):
|
||||||
extra = self.parameterAsString(parameters, self.EXTRA, context)
|
extra = self.parameterAsString(parameters, self.EXTRA, context)
|
||||||
|
@ -339,6 +339,7 @@ class TestGdalAlgorithms(unittest.TestCase):
|
|||||||
|
|
||||||
def testEscapeAndJoin(self):
|
def testEscapeAndJoin(self):
|
||||||
self.assertEqual(GdalUtils.escapeAndJoin([1, "a", "a b", "a&b", "a(b)", ";"]), '1 a "a b" "a&b" "a(b)" ";"')
|
self.assertEqual(GdalUtils.escapeAndJoin([1, "a", "a b", "a&b", "a(b)", ";"]), '1 a "a b" "a&b" "a(b)" ";"')
|
||||||
|
self.assertEqual(GdalUtils.escapeAndJoin([1, "-srcnodata", "--srcnodata", "-9999 9999"]), '1 -srcnodata --srcnodata "-9999 9999"')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -2606,7 +2606,7 @@ class TestGdalRasterAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsT
|
|||||||
cmd[1] = t[:t.find('-input_file_list') + 17] + t[t.find('buildvrtInputFiles.txt'):]
|
cmd[1] = t[:t.find('-input_file_list') + 17] + t[t.find('buildvrtInputFiles.txt'):]
|
||||||
self.assertEqual(cmd,
|
self.assertEqual(cmd,
|
||||||
['gdalbuildvrt',
|
['gdalbuildvrt',
|
||||||
'-resolution average -separate -r nearest -srcnodata "-9999" ' +
|
'-resolution average -separate -r nearest -srcnodata -9999 ' +
|
||||||
'-input_file_list buildvrtInputFiles.txt ' +
|
'-input_file_list buildvrtInputFiles.txt ' +
|
||||||
outdir + '/check.vrt'])
|
outdir + '/check.vrt'])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user