Skip to content
Permalink
Browse files

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

(cherry picked from commit bfdb99f)
  • Loading branch information
alexbruy authored and nyalldawson committed Nov 20, 2020
1 parent 4b9d9cf commit ee88c428bb2301cae5bd3fdab230153a4ec6e9b8
@@ -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:
@@ -332,7 +332,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 ee88c42

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