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 committed Mar 3, 2017
1 parent c279a3e commit 0fe9916
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fluent/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def parse(text)
end

class ApacheParser < Parser
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/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ def test_parse_without_http_version
assert_equal(@expected, record)
}
end

def test_parse_with_escape_sequence
@parser.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

class SyslogParserTest < ::Test::Unit::TestCase
Expand Down

0 comments on commit 0fe9916

Please sign in to comment.