-
Notifications
You must be signed in to change notification settings - Fork 110
Add cgi_mode to parse_header to support LF in CGI headers #166
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
47dd05b
ee1d7ba
84e865a
4ab4c2d
efa1987
32887fd
b6dd139
b7b3d61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,17 +168,22 @@ def join(separator = "; ") | |
| "cookie" => CookieHeader, | ||
| }) | ||
|
|
||
| def parse_header(raw) | ||
| def parse_header(raw, cgi_mode = false) | ||
paulownia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| header = Hash.new([].freeze) | ||
| field = nil | ||
|
|
||
| line_break = cgi_mode ? "\\r?\\n" : "\\r\\n" | ||
| header_line = Regexp.new(/^([A-Za-z0-9!\#$%&'*+\-.^_`|~]+):([^\r\n\0]*?)#{line_break}\z/m) | ||
| continued_header_lines = Regexp.new(/^[ \t]+([^\r\n\0]*?)#{line_break}/m) | ||
|
||
|
|
||
| raw.each_line{|line| | ||
| case line | ||
| when /^([A-Za-z0-9!\#$%&'*+\-.^_`|~]+):([^\r\n\0]*?)\r\n\z/om | ||
| when header_line | ||
| field, value = $1, $2 | ||
| field.downcase! | ||
| header[field] = HEADER_CLASSES[field].new unless header.has_key?(field) | ||
| header[field] << value | ||
| when /^[ \t]+([^\r\n\0]*?)\r\n/om | ||
| when continued_header_lines | ||
| unless field | ||
| raise HTTPStatus::BadRequest, "bad header '#{line}'." | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ module WEBrick | |
|
|
||
| HEADER_CLASSES: Hash[String, untyped] | ||
|
|
||
| def self?.parse_header: (String raw) -> Hash[String, Array[String]] | ||
| def self?.parse_header: (String raw, ?bool cgi_mode) -> Hash[String, Array[String]] | ||
|
||
|
|
||
| def self?.split_header_value: (String str) -> Array[String] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!ruby | ||
|
|
||
| body = "test for bare LF in cgi header" | ||
|
|
||
| print "Content-Type: text/plain\n" | ||
| print "Content-Length: #{body.size}\n" | ||
| print "\n" | ||
| print body |
Uh oh!
There was an error while loading. Please reload this page.