kronenthaler / openstep-parser

OpenStep plist parser for python
BSD 2-Clause "Simplified" License
17 stars 17 forks source link

KeyError: u'&' in projects containing the letter `&` #15

Closed maggix closed 4 years ago

maggix commented 6 years ago

Hello,

when running the script to add a new build phase, I get this error: KeyError: u'&'

Script:

from pbxproj import XcodeProject
import sys

with open('xcode-script-strip-archs.sh', 'r') as myfile:
  script1 = myfile.read()  

#docs: https://github.com/kronenthaler/mod-pbxproj/wiki/flags#run-script
project = XcodeProject.load("./platforms/ios/M&R.xcodeproj/project.pbxproj")
project.add_run_script(script1,  None, False)
project.save()

Trackback:

Traceback (most recent call last):
  File "add-fix-server-port-xcode.py", line 11, in <module>
    project = XcodeProject.load("./platforms/ios/M&R.xcodeproj/project.pbxproj")
  File "/usr/local/lib/python2.7/site-packages/pbxproj/XcodeProject.py", line 64, in load
    tree = osp.OpenStepDecoder.ParseFromFile(open(path, 'r'))
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 43, in ParseFromFile
    return cls.ParseFromString(fp.read().decode('UTF-8'))
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 47, in ParseFromString
    return OpenStepDecoder()._parse(str)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 56, in _parse
    result, index = self._parse_dictionary(str, index)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 68, in _parse_dictionary
    index = self._parse_dictionary_entry(str, index, obj)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 98, in _parse_dictionary_entry
    value, index = self._parse_value(str, index)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 170, in _parse_value
    value, index = self._parse_dictionary(str, index)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 68, in _parse_dictionary
    index = self._parse_dictionary_entry(str, index, obj)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 98, in _parse_dictionary_entry
    value, index = self._parse_value(str, index)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 170, in _parse_value
    value, index = self._parse_dictionary(str, index)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 68, in _parse_dictionary
    index = self._parse_dictionary_entry(str, index, obj)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 98, in _parse_dictionary_entry
    value, index = self._parse_value(str, index)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 174, in _parse_value
    value, index = self._parse_literal(str, index)
  File "/usr/local/lib/python2.7/site-packages/openstep_parser/openstep_parser.py", line 148, in _parse_literal
    key += d[str[index]]
KeyError: u'&'

How do I properly pass the & character in the path to the script? I tried escaping with \ without success.

thank you

kronenthaler commented 6 years ago

Thanks for the report, It looks like a parsing error. The problem is no on the path of the file, but internally in the project itself there is a reference to the project name with a & that is breaking the parsing.

What you can check is, open the project.pbxproj in a text editor, look for the occurrences of M&R within the project, what you should find is something like name = M&R; try enclosing the M&R within double quotes name = "M&R";

At least this will give me some pointers where to start looking at.

maggix commented 6 years ago

Hi @kronenthaler ! Thanks for the reply. The file is full of references of M&R as it's the name of the file, the name of the main target, ... the name of everything fundamentally!

I hope I will be able to follow-up but in urgency I currently switched to the "competition" ;) to overcome the issue (hope you don't mind!)

kronenthaler commented 6 years ago

No offense taken, i will investigate the issue when i have free time.

github-actions[bot] commented 4 years ago

This issue has become stale, the required information has not been provided and it is been marked for closure in the next 5 days