Legoktm has uploaded a new change for review. https://gerrit.wikimedia.org/r/196306
Change subject: check_php_syntax: Check for any content before opening <?php tag ...................................................................... check_php_syntax: Check for any content before opening <?php tag Some commandline scripts do start with a shebang, so allow those. Bug: T92534 Change-Id: I63018163fc740db9b475129113bbee809a8db0c9 --- M scap/tasks.py 1 file changed, 19 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/scap refs/changes/06/196306/1 diff --git a/scap/tasks.py b/scap/tasks.py index f47eed0..bef2ef3 100644 --- a/scap/tasks.py +++ b/scap/tasks.py @@ -85,7 +85,25 @@ "| xargs -n1 -P%d -exec php -l >/dev/null" ) % (' '.join(quoted_paths), multiprocessing.cpu_count()) logger.debug('Running command: `%s`', cmd) - return subprocess.check_call(cmd, shell=True) + subprocess.check_call(cmd, shell=True) + # Check for anything that isn't a shebang before <?php (T92534) + for path in paths: + for root, dirs, files in os.walk(path): + for filename in files: + if filename.endswith(('.php', '.inc', '.phtml')): + full_path = os.path.join(root, filename) + with open(full_path) as f: + text = f.read() + if not text.startswith('<?php'): + # If the first line is a shebang and the + # second has <?php, that's ok + lines = text.splitlines() + if not (lines[0].startswith('#!') + and lines[1].startswith('<?php')): + raise ValueError( + '%s has content before opening <?php tag' + % full_path + ) def compile_wikiversions_cdb(source_tree, cfg): -- To view, visit https://gerrit.wikimedia.org/r/196306 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I63018163fc740db9b475129113bbee809a8db0c9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/tools/scap Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits