From 4a40799ccdc2d8a0b4d1991fd5226365a75c8cfa Mon Sep 17 00:00:00 2001 From: Michal Szelag Date: Wed, 10 Apr 2024 03:53:57 -0400 Subject: [PATCH] fix: build step parsing that includes newlines (#344) --- pbxproj/PBXGenericObject.py | 3 ++- tests/TestPBXGenericObject.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pbxproj/PBXGenericObject.py b/pbxproj/PBXGenericObject.py index 658f4c6..0ad00d4 100644 --- a/pbxproj/PBXGenericObject.py +++ b/pbxproj/PBXGenericObject.py @@ -10,7 +10,8 @@ class PBXGenericObject(object): Generic class that creates internal attributes to match the structure of the tree used to create the element. Also, prints itself using the openstep format. Extensions might be required to insert comments on right places. """ - _VALID_KEY_REGEX = re.compile(r'^[a-zA-Z0-9\\._/]*$') + # use negative look-ahead to avoid matching the newline character in multiline strings + _VALID_KEY_REGEX = re.compile(r'^[a-zA-Z0-9\\._/]*(?!\n)$') _ESCAPE_REPLACEMENTS = [ ('\\', '\\\\'), ('\n', '\\n'), diff --git a/tests/TestPBXGenericObject.py b/tests/TestPBXGenericObject.py index e2cfddb..ab0c3ed 100644 --- a/tests/TestPBXGenericObject.py +++ b/tests/TestPBXGenericObject.py @@ -27,6 +27,7 @@ def testParseKey(self): def testEscapeItem(self): assert PBXGenericObject._escape("/bin/sh") == "/bin/sh" + assert PBXGenericObject._escape("/bin/sh\n") == '"/bin/sh\\n"' assert PBXGenericObject._escape("abcdefghijklmnopqrstuvwyz0123456789") == \ "abcdefghijklmnopqrstuvwyz0123456789" assert PBXGenericObject._escape("some spaces") == '"some spaces"'