Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect malformed closing tags as errors in ApacheConfLexer #1656

Merged
merged 1 commit into from Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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