diff --git a/babi/theme.py b/babi/theme.py index ce112f0..2b167fe 100644 --- a/babi/theme.py +++ b/babi/theme.py @@ -114,11 +114,14 @@ class Theme(NamedTuple): for rule in rules: if 'scope' not in rule: scopes = [''] + elif rule['scope'] == '': + scopes = [''] elif isinstance(rule['scope'], str): scopes = [ s.strip() # some themes have a buggy trailing/leading comma for s in rule['scope'].strip().strip(',').split(',') + if s.strip() ] else: scopes = rule['scope'] diff --git a/tests/theme_test.py b/tests/theme_test.py index a4a1d8d..6cd00f8 100644 --- a/tests/theme_test.py +++ b/tests/theme_test.py @@ -84,6 +84,19 @@ def test_theme_scope_comma_at_beginning_and_end(): assert theme.select(('b',)).i is True +def test_theme_scope_internal_newline_commas(): + # this is arguably malformed, but `cobalt2` in the wild has this issue + theme = Theme.from_dct({ + 'colors': {'foreground': '#cccccc', 'background': '#333333'}, + 'tokenColors': [ + {'scope': '\n,a,\n,b,\n', 'settings': {'fontStyle': 'italic'}}, + ], + }) + assert theme.select(('d',)).i is False + assert theme.select(('a',)).i is True + assert theme.select(('b',)).i is True + + def test_theme_scope_as_A_list(): theme = Theme.from_dct({ 'colors': {'foreground': '#cccccc', 'background': '#333333'},