Skip to content
Permalink
Browse files

[processing] correctly escape parentheses in GDAL command (fix #39525)

  • Loading branch information
alexbruy authored and nyalldawson committed Oct 27, 2020
1 parent 8ba0606 commit bfdb99fe6592813ab8b9ec98bfe8adf463323877
@@ -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:
@@ -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__':

0 comments on commit bfdb99f

Please sign in to comment.
You can’t perform that action at this time.