Skip to content

Commit

Permalink
Detect malformed closing tags as errors. (#1656)
Browse files Browse the repository at this point in the history
  • Loading branch information
catatonicprime committed Jan 6, 2021
1 parent f58638e commit effe7c3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pygments/lexers/configs.py
Expand Up @@ -302,8 +302,10 @@ class ApacheConfLexer(RegexLexer):
'root': [
(r'\s+', Text),
(r'#(.*\\\n)+.*$|(#.*?)$', Comment),
(r'(<[^\s>]+)(?:(\s+)(.*))?(>)',
(r'(<[^\s>/][^\s>]*)(?:(\s+)(.*))?(>)',
bygroups(Name.Tag, Text, String, Name.Tag)),
(r'(</[^\s>]+)(>)',
bygroups(Name.Tag, Name.Tag)),
(r'[a-z]\w*', Name.Builtin, 'value'),
(r'\.+', Text),
],
Expand Down
33 changes: 33 additions & 0 deletions tests/test_apache_conf.py
Expand Up @@ -99,3 +99,36 @@ def test_fix_lock_absolute_path(lexer):
(Token.Text, '\n'),
]
assert list(lexer.get_tokens(fragment)) == tokens

def test_normal_scoped_directive(lexer):
fragment = '<VirtualHost "test">\n</VirtualHost>'
tokens = [
(Token.Name.Tag, '<VirtualHost'),
(Token.Text, ' '),
(Token.Literal.String, '"test"'),
(Token.Name.Tag, '>'),
(Token.Text, '\n'),
(Token.Name.Tag, '</VirtualHost'),
(Token.Name.Tag, '>'),
(Token.Text, '\n')
]
assert list(lexer.get_tokens(fragment)) == tokens

def test_malformed_scoped_directive_closing_tag(lexer):
fragment = '<VirtualHost "test">\n</VirtualHost\n>'
tokens = [
(Token.Name.Tag, '<VirtualHost'),
(Token.Text, ' '),
(Token.Literal.String, '"test"'),
(Token.Name.Tag, '>'),
(Token.Text, '\n'),
(Token.Error, '<'),
(Token.Error, '/'),
(Token.Name.Builtin, 'VirtualHost'),
(Token.Text, ''),
(Token.Text, '\n'),
(Token.Error, '>'),
(Token.Text, '\n')
]
assert list(lexer.get_tokens(fragment)) == tokens

0 comments on commit effe7c3

Please sign in to comment.