Skip to content

Commit

Permalink
[processing] correctly escape parentheses in GDAL command (fix #39525)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Oct 28, 2020
1 parent 4af1cbf commit 8d7f8ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/plugins/processing/algs/gdal/GdalUtils.py
Expand Up @@ -217,11 +217,12 @@ def getFormatShortNameFromFilename(filename):

@staticmethod
def escapeAndJoin(strList):
escChars = [' ', '&', '(', ')']
joined = ''
for s in strList:
if not isinstance(s, str):
s = str(s)
if s and s[0] != '-' and (' ' in s or '&' in s):
if s and s[0] != '-' and any(c in s for c in escChars):
escaped = '"' + s.replace('\\', '\\\\').replace('"', '\\"') \
+ '"'
else:
Expand Down
Expand Up @@ -349,7 +349,7 @@ def testCrsConversion(self):
'+proj=utm +zone=36 +south +a=600000 +b=70000 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs')

def testEscapeAndJoin(self):
self.assertEqual(GdalUtils.escapeAndJoin([1, "a", "a b", "a&b"]), '1 a "a b" "a&b"')
self.assertEqual(GdalUtils.escapeAndJoin([1, "a", "a b", "a&b", "a(b)"]), '1 a "a b" "a&b" "a(b)"')


if __name__ == '__main__':
Expand Down

0 comments on commit 8d7f8ed

Please sign in to comment.