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"'