From 4acbff6afff1a48eb042da1762fbaa0f2ce5be31 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 4 Mar 2022 17:39:42 +0100 Subject: [PATCH] Syntax: Restrict AssignSyntaxTestSyntaxListener Fixes #365 This commit restricts execution of `on_load()` to `syntax_test_` files located within ST's packages path. Note: Hard coded path separators such as `/` don't work on Windows and therefore must not be used. --- plugins/syntaxtest_dev.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/syntaxtest_dev.py b/plugins/syntaxtest_dev.py index 6cef16b4..7ea1a89c 100644 --- a/plugins/syntaxtest_dev.py +++ b/plugins/syntaxtest_dev.py @@ -435,7 +435,15 @@ class AssignSyntaxTestSyntaxListener(sublime_plugin.EventListener): PLAIN_TEXT = "Packages/Text/Plain text.tmLanguage" def on_load(self, view): - if view.size() == 0 and view.file_name().startswith(sublime.packages_path() + '/'): + file_name = view.file_name() + if not file_name: + return + folder_name, file_name = path.split(file_name) + if not file_name.startswith('syntax_test_'): + return + if not folder_name.startswith(sublime.packages_path()): + return + if view.size() == 0: logger.debug("Delaying on_load because view was empty") sublime.set_timeout(lambda: self._on_load(view), 100) else: