Skip to content

Commit

Permalink
Syntax: Restrict AssignSyntaxTestSyntaxListener
Browse files Browse the repository at this point in the history
Fixes SublimeText#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.
  • Loading branch information
deathaxe committed Mar 4, 2022
1 parent 21e3b52 commit 4acbff6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plugins/syntaxtest_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4acbff6

Please sign in to comment.