Skip to content

Commit

Permalink
Permit an empty reason-phrase element in HTTP lexer (#1313)
Browse files Browse the repository at this point in the history
The HTTP 1.1 spec permits empty reason-phrase elements in HTTP
responses but the HTTP lexer requires a reason-phrase to be given. This
commit removes that requirement.
  • Loading branch information
pyrmont committed Aug 30, 2019
1 parent 1c44039 commit fdbf747
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/http.rb
Expand Up @@ -42,7 +42,7 @@ def content_lexer
rule %r(
(HTTPS?)(/)(\d(?:\.\d))([ ]+) # http version
(\d{3})([ ]+)? # status
([^\r\n]+)?(\r?\n|$) # status message
([^\r\n]*)?(\r?\n|$) # status message
)x do
groups(
Keyword, Operator, Num, Text,
Expand Down
14 changes: 12 additions & 2 deletions spec/lexers/http_spec.rb
Expand Up @@ -5,7 +5,7 @@
let(:subject) { Rouge::Lexers::HTTP.new }
include Support::Lexing

it 'lexes HTTP/2' do
it 'lexes a HTTP/2 request' do
request = "GET / HTTP/2"
assert_tokens_equal request, ["Name.Function", "GET"],
["Text", " "],
Expand All @@ -16,7 +16,7 @@
["Literal.Number", "2"]
end

it 'lexes HTTP/1.1' do
it 'lexes a HTTP/1.1 request' do
request = "GET / HTTP/1.1"
assert_tokens_equal request, ["Name.Function", "GET"],
["Text", " "],
Expand All @@ -26,4 +26,14 @@
["Operator", "/"],
["Literal.Number", "1.1"]
end

it 'lexes an empty HTTP/1.1 response' do
response = "HTTP/1.1 200 "
assert_tokens_equal response, ["Keyword", "HTTP"],
["Operator", "/"],
["Literal.Number", "1.1"],
["Text", " "],
["Literal.Number", "200"],
["Text", " "]
end
end

0 comments on commit fdbf747

Please sign in to comment.