Skip to content

Commit

Permalink
Merge pull request #1479 from sergeyfedotov/allow_escape_sequence
Browse files Browse the repository at this point in the history
Allow escape sequence in Apache access log
  • Loading branch information
repeatedly authored Mar 2, 2017
2 parents 065a063 + df5ac35 commit 27bff7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fluent/plugin/parser_apache2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Plugin
class Apache2Parser < Parser
Plugin.register_parser('apache2', self)

REGEXP = /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/
REGEXP = /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>(?:[^\"]|\\.)*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>(?:[^\"]|\\.)*)" "(?<agent>(?:[^\"]|\\.)*)")?$/
TIME_FORMAT = "%d/%b/%Y:%H:%M:%S %z"

def initialize
Expand Down
8 changes: 8 additions & 0 deletions test/plugin/test_parser_apache2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ def test_parse_without_http_version
assert_equal(@expected, record)
}
end

def test_parse_with_escape_sequence
@parser.instance.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET /\" HTTP/1.1" 200 777 "referer \\\ \"" "user agent \\\ \""') { |_, record|
assert_equal('/\"', record['path'])
assert_equal('referer \\\ \"', record['referer'])
assert_equal('user agent \\\ \"', record['agent'])
}
end
end

0 comments on commit 27bff7b

Please sign in to comment.