[MIRROR] Fix quote handling in dmi.py script and add it to CI (#799)

* Fix quote handling in dmi.py script and add it to CI (#53669)

* Handle escape sequences in .dmi metadata

* Improve dmi.py self-test functionality

* Add dmi self-test to CI

* Install requirements for CI

* Fix quote handling in dmi.py script and add it to CI

Co-authored-by: Tad Hardesty <tad@platymuus.com>
This commit is contained in:
SkyratBot
2020-09-14 11:22:18 +02:00
committed by GitHub
co-authored by Tad Hardesty
parent 2e33ca3ef8
commit 5cf715300d
2 changed files with 31 additions and 4 deletions
+1
View File
@@ -32,6 +32,7 @@ jobs:
- find . -name "*.json" -not -path "*/node_modules/*" -print0 | xargs -0 python3 ./tools/json_verifier.py
- tools/travis/build_tgui.sh
- tools/travis/check_grep.sh
- python3 -m pip install -r tools/mapmerge2/requirements.txt && python3 tools/mapmerge2/dmi.py --test
- ~/dreamchecker
- name: "Compile All Maps"
+30 -4
View File
@@ -217,7 +217,8 @@ class State:
return self.frames[self._frame_index(*args, **kwargs)]
def escape(text):
assert '\\' not in text and '"' not in text
text = text.replace('\\', '\\\\')
text = text.replace('"', '\\"')
return f'"{text}"'
def unescape(text, quote='"'):
@@ -226,7 +227,8 @@ def unescape(text, quote='"'):
if not (text.startswith(quote) and text.endswith(quote)):
raise ValueError(text)
text = text[1:-1]
assert '\\' not in text and quote not in text
text = text.replace('\\"', '"')
text = text.replace('\\\\', '\\')
return text
def parse_num(value):
@@ -239,7 +241,7 @@ def parse_bool(value):
raise ValueError(value)
return value == '1'
if __name__ == '__main__':
def _self_test():
# test: can we load every DMI in the tree
import os
@@ -249,7 +251,31 @@ if __name__ == '__main__':
dirnames.remove('.git')
for filename in filenames:
if filename.endswith('.dmi'):
Dmi.from_file(os.path.join(dirpath, filename))
fullpath = os.path.join(dirpath, filename)
try:
Dmi.from_file(fullpath)
except:
print('Failed on:', fullpath)
raise
count += 1
print(f"Successfully parsed {count} dmi files")
def _usage():
import sys
print(f"Usage:")
print(f" {sys.argv[0]} --test")
exit(1)
def _main():
import sys
if len(sys.argv) < 2:
return _usage()
if sys.argv[1] == '--test':
return _self_test()
return _usage()
if __name__ == '__main__':
_main()