Skip to content
Permalink
Browse files

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

  • Loading branch information
github-actions authored and nyalldawson committed Oct 28, 2020
1 parent 4af1cbf commit 8d7f8ed3eb3cbd084b60646e6690eecfd1db7d22
@@ -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 8d7f8ed

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