fix for internal extra commas in theme scopes

This commit is contained in:
Anthony Sottile
2020-03-17 12:13:36 -07:00
parent e32e5b8c05
commit e77a660029
2 changed files with 16 additions and 0 deletions

View File

@@ -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']

View File

@@ -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'},