server_log_parser 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99d0578102face3c2664838e749c0de0192322ab
4
- data.tar.gz: 8d2030582ca02f1e9cd98ee0f773be0baeb0e7d1
3
+ metadata.gz: d3822fbfb155d2237d6637152c03a9447a426f6c
4
+ data.tar.gz: 80160b6064711a43c94bfe5a367dcabf03f8d533
5
5
  SHA512:
6
- metadata.gz: a677d61e5c9ffadf121726262b38b05b19c49883ce5f1b0f4bcb223ce3c04dfdd9c4489179c510213e54931255c9b90140fad2dcc985190dd9ee3af5aabf8d15
7
- data.tar.gz: 34176519e78657e8e67c4639d4baa1a7faf92af489e8e2d26027cda42fe3cfad8a57703acc0e6d193af53fcb510a8380d612e08187541cfdea6b5522591421d4
6
+ metadata.gz: 746b9986ac7183eb3397aff0b28e90a1c82cbb387c3116d3937219acdc1c5b030af62384a13407e19f0f7bad48c5e6480ecd48f34544e99ba2d0abd74dde894f
7
+ data.tar.gz: 1a8a50ebb3ed4750d1580bf604f12af65a2871e3b577b159d10912d046f40ed259cc66a1b141bf4e166b6ba1413c6f51b0c6a595769d8e4493d0ec2eb547a85b
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "rake/testtask"
2
2
  Rake::TestTask.new do |t|
3
3
  t.libs << "test"
4
- t.test_files = FileList['test/*_test.rb']
4
+ t.test_files = FileList['test/**/*_test.rb']
5
5
  t.verbose = true
6
6
  end
7
7
 
@@ -91,25 +91,20 @@ module ServerLogParser
91
91
  format.strip! # remove leading and trailing space
92
92
  format.gsub!(/[ \t]+/, ' ') # replace tabulations or spaces with a space
93
93
 
94
- strip_quotes = proc { |string| string.gsub(/^\\"/, '').gsub(/\\"$/, '') }
95
- find_quotes = proc { |string| string =~ /^\\"/ }
96
- find_percent = proc { |string| string =~ /^%.*t$/ }
97
- find_referrer_or_useragent = proc { |string| string =~ /Referer|User-Agent/ }
98
-
99
94
  pattern = format.split(' ').map do |element|
100
- has_quotes = !!find_quotes.call(element)
101
- element = strip_quotes.call(element) if has_quotes
95
+ has_quotes = element =~ /^\\"/
96
+ element = element.gsub(/^\\"/, '').gsub(/\\"$/, '') if has_quotes
102
97
 
103
98
  self.names << rename_this_name(element)
104
99
 
105
100
  case
106
101
  when has_quotes
107
- if element == '%r' or find_referrer_or_useragent.call(element)
102
+ if element == '%r' || element =~ /^%{Referer}/ || element =~ /^%{User-agent}/
108
103
  /"([^"\\]*(?:\\.[^"\\]*)*)"/
109
104
  else
110
105
  '\"([^\"]*)\"'
111
106
  end
112
- when find_percent.call(element)
107
+ when element =~ /^%.*t$/
113
108
  '(\[[^\]]+\])'
114
109
  when element == '%U'
115
110
  '(.+?)'
@@ -1,5 +1,5 @@
1
1
  module ServerLogParser
2
2
 
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
 
5
5
  end
@@ -0,0 +1 @@
1
+ 212.74.15.68 - - [23/Jan/2004:11:36:20 +0000] "GET /images/previous.png HTTP/1.1" 200 2607 "http://peterhi.dyndns.org/bandwidth/index.html" "Mozilla/5.0 (X11; U; Linux \"Superman\\Superwoman\" i686; en-US; rv:1.2) Gecko/20021202"
@@ -13,7 +13,7 @@ describe ServerLogParser::Parser do
13
13
  end
14
14
 
15
15
  before do
16
- @format = '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"'
16
+ @format = '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"'
17
17
  @parser = ServerLogParser::Parser.new(@format)
18
18
  end
19
19
 
@@ -28,7 +28,7 @@ describe ServerLogParser::Parser do
28
28
  '%>s' => '200',
29
29
  '%b' => '2607',
30
30
  '%{Referer}i' => 'http://peterhi.dyndns.org/bandwidth/index.html',
31
- '%{User-Agent}i' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202' }
31
+ '%{User-agent}i' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202' }
32
32
  results = @parser.parse(read_testcase('line.log'))
33
33
 
34
34
  assert_kind_of(Hash, results)
@@ -44,8 +44,24 @@ describe ServerLogParser::Parser do
44
44
  '%>s' => '200',
45
45
  '%b' => '2607',
46
46
  '%{Referer}i' => 'http://peterhi.dyndns.org/bandwidth/index.html',
47
- '%{User-Agent}i' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202' }
48
- results = @parser.parse(read_testcase('line-with-slash-quote-in-request.log'))
47
+ '%{User-agent}i' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202' }
48
+ results = @parser.parse(read_testcase('line_with_slash_quote_in_request.log'))
49
+
50
+ assert_kind_of(Hash, results)
51
+ assert_match_expected_hash(expected, results)
52
+ end
53
+
54
+ it "should parse line with slash quote in user agent" do
55
+ expected = { '%h' => '212.74.15.68',
56
+ '%l' => '-',
57
+ '%u' => '-',
58
+ '%t' => '[23/Jan/2004:11:36:20 +0000]',
59
+ '%r' => 'GET /images/previous.png HTTP/1.1',
60
+ '%>s' => '200',
61
+ '%b' => '2607',
62
+ '%{Referer}i' => 'http://peterhi.dyndns.org/bandwidth/index.html',
63
+ '%{User-agent}i' => 'Mozilla/5.0 (X11; U; Linux \\"Superman\\\\Superwoman\\" i686; en-US; rv:1.2) Gecko/20021202' }
64
+ results = @parser.parse(read_testcase('line_with_slash_quote_in_user-agent.log'))
49
65
 
50
66
  assert_kind_of(Hash, results)
51
67
  assert_match_expected_hash(expected, results)
@@ -60,8 +76,8 @@ describe ServerLogParser::Parser do
60
76
  '%>s' => '200',
61
77
  '%b' => '2888',
62
78
  '%{Referer}i' => 'http://search.yahoo.com/bin/search?p=\"grady%20white%20306%20bimini\"',
63
- '%{User-Agent}i' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; YPC 3.0.3; yplus 4.0.00d)' }
64
- results = @parser.parse(read_testcase('line-with-slash-quote-in-referer.log'))
79
+ '%{User-agent}i' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; YPC 3.0.3; yplus 4.0.00d)' }
80
+ results = @parser.parse(read_testcase('line_with_slash_quote_in_referer.log'))
65
81
 
66
82
  assert_kind_of(Hash, results)
67
83
  assert_match_expected_hash(expected, results)
@@ -104,7 +120,7 @@ describe ServerLogParser::Parser do
104
120
  '%>s' => 200,
105
121
  '%b' => 2607,
106
122
  '%{Referer}i' => 'http://peterhi.dyndns.org/bandwidth/index.html',
107
- '%{User-Agent}i' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202' }
123
+ '%{User-agent}i' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202' }
108
124
  results = @parser.handle(read_testcase('line.log'))
109
125
 
110
126
  assert_kind_of(Hash, results)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: server_log_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kurakin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,10 +71,11 @@ files:
71
71
  - lib/server_log_parser/parser.rb
72
72
  - lib/server_log_parser/version.rb
73
73
  - server_log_parser.gemspec
74
- - test/fixtures/line-with-slash-quote-in-referer.log
75
- - test/fixtures/line-with-slash-quote-in-request.log
76
74
  - test/fixtures/line.log
77
- - test/parser_test.rb
75
+ - test/fixtures/line_with_slash_quote_in_referer.log
76
+ - test/fixtures/line_with_slash_quote_in_request.log
77
+ - test/fixtures/line_with_slash_quote_in_user-agent.log
78
+ - test/server_log_parser/parser_test.rb
78
79
  - test/server_log_parser_test.rb
79
80
  - test/test_helper.rb
80
81
  homepage: https://github.com/kuraga/server_log_parser
@@ -102,9 +103,10 @@ signing_key:
102
103
  specification_version: 4
103
104
  summary: Ruby library to parse Apache server log files using regular expressions.
104
105
  test_files:
105
- - test/fixtures/line-with-slash-quote-in-referer.log
106
- - test/fixtures/line-with-slash-quote-in-request.log
107
106
  - test/fixtures/line.log
108
- - test/parser_test.rb
107
+ - test/fixtures/line_with_slash_quote_in_referer.log
108
+ - test/fixtures/line_with_slash_quote_in_request.log
109
+ - test/fixtures/line_with_slash_quote_in_user-agent.log
110
+ - test/server_log_parser/parser_test.rb
109
111
  - test/server_log_parser_test.rb
110
112
  - test/test_helper.rb