akita-har_logger 0.2.5 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1a952e08b6244134dc4498e24b7185a700fe6d60abdc257bae8e5c3f67a57c6
4
- data.tar.gz: 205780425d013375017a8677630c68c078b3be55772ebc0bebf0968d8e16601b
3
+ metadata.gz: c1366b8824f9cd610742238604c0d162845132a67dd67e9763542ae271cf0b7d
4
+ data.tar.gz: 2ca5e09f1f65045405ce549b194fa4a51573663f43e1f3ecdde5c73d930538c2
5
5
  SHA512:
6
- metadata.gz: 0beadf21aa88256c40d0b6bc4c2e0c54dae7656aea1cd472b8ae7a610484969f70ed9239c3a783362eaf68be41c373085cb181eb456bce413510e8f50d5a50ed
7
- data.tar.gz: 622997ac27c899f809b1d7c632ca0da6f8916f00a25b9cdb22d8d6861b1107c8226cfd7802c9b03745d774268780d066db5bcb739081a06c66cd89cee235016a
6
+ metadata.gz: 82b07817b21e2e05c0f5c5139370c7bdd9b712dcd02e134b9d52be1d1ce95a00e4ff200067c0797a9be1a1f2b56a0518a2fac0526696bb3de3700f8f58c9bd44
7
+ data.tar.gz: 45ea9d1c479cb47f481c1b3fb7eba1dc8032dc692dc69d478e8cba98b2abb14d94e685efff5d5591785a871ddecc787166c99f70ceb2d99fc5f6961803f27a49
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- akita-har_logger (0.2.5)
4
+ akita-har_logger (0.2.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,15 +9,26 @@ module Akita
9
9
  # If we are unable to do this reinterpretation, return the string
10
10
  # unchanged, but log a warning that points to the caller.
11
11
  def self.fixEncoding(v)
12
- if v != nil && v.encoding == Encoding::ASCII_8BIT then
13
- forced = String.new(v).force_encoding(Encoding::UTF_8)
14
- if forced.valid_encoding? then
15
- v = forced
16
- else
17
- Rails.logger.warn "[#{caller_locations(1, 1)}] Unable to fix encoding: not a valid UTF-8 string. This will likely cause JSON serialization to fail."
18
- end
12
+ if v == nil then
13
+ return v
14
+ end
15
+
16
+ if !(v.is_a? String) then
17
+ Rails.logger.warn "[#{caller_locations(1, 1)}] fixEncoding was not given a string. This might cause JSON serialization to fail."
18
+ return v
19
+ end
20
+
21
+ # Only re-interpret 8-bit ASCII.
22
+ if v.encoding != Encoding::ASCII_8BIT then
23
+ return v
24
+ end
25
+
26
+ forced = String.new(v).force_encoding(Encoding::UTF_8)
27
+ if forced.valid_encoding? then
28
+ return forced
19
29
  end
20
30
 
31
+ Rails.logger.warn "[#{caller_locations(1, 1)}] Unable to fix encoding: not a valid UTF-8 string. This will likely cause JSON serialization to fail."
21
32
  v
22
33
  end
23
34
 
@@ -28,7 +39,7 @@ module Akita
28
39
  hash.reduce([]) { |accum, (k, v)|
29
40
  accum.append({
30
41
  name: fixEncoding(k),
31
- value: fixEncoding(v),
42
+ value: fixEncoding(v.to_s),
32
43
  })
33
44
  }
34
45
  end
@@ -85,7 +85,7 @@ module Akita
85
85
  return Encoding::ISO_8859_1
86
86
  end
87
87
 
88
- Encoding::ASCII_8BIT
88
+ Encoding::UTF_8
89
89
  end
90
90
 
91
91
  # Obtains the posted data from an HTTP environment.
@@ -121,7 +121,8 @@ module Akita
121
121
  # Gracefully handle any characters that are invalid in the source
122
122
  # encoding and characters that have no UTF-8 representation by
123
123
  # replacing with '?'. Log a warning when this happens.
124
- source = req.body.string.force_encoding(getPostDataCharSet(env))
124
+ sourceCharset = getPostDataCharSet(env)
125
+ source = String.new(req.body.string).force_encoding(sourceCharset)
125
126
  utf8EncodingSuccessful = false
126
127
  if source.valid_encoding? then
127
128
  begin
@@ -74,14 +74,51 @@ module Akita
74
74
  end
75
75
 
76
76
  def getContent(headers, body)
77
- # XXX Handle compression & encoding.
77
+ # XXX Handle compression
78
+ # XXX Figure out how to properly join together multi-part bodies.
78
79
 
80
+ # Try to convert the body into UTF-8. If this fails, assume the body is
81
+ # binary data.
82
+ # XXX TODO Take charset part of Content-Type header into account.
79
83
  text = +""
84
+ haveBinaryData = false
80
85
  body.each { |part|
81
- # XXX Figure out how to join together multi-part bodies.
82
- text << (HarUtils.fixEncoding part);
86
+ partStr = part.to_s
87
+
88
+ if partStr.encoding == Encoding::ASCII_8BIT then
89
+ # Have 8-bit ASCII data. Try to interpret as UTF-8. If this fails,
90
+ # treat as binary data.
91
+ forced = String.new(partStr).force_encoding(Encoding::UTF_8)
92
+ if forced.valid_encoding? then
93
+ text << forced
94
+ next
95
+ end
96
+
97
+ haveBinaryData = true
98
+ break
99
+ end
100
+
101
+ if !partStr.valid_encoding? then
102
+ # Source encoding is not valid. Treat as binary data.
103
+ haveBinaryData = true
104
+ break
105
+ end
106
+
107
+ # Try to re-encode as UTF-8. If this fails, treat as binary data.
108
+ begin
109
+ text << partStr.encode(Encoding::UTF_8)
110
+ rescue Encoding::UndefinedConversionError
111
+ haveBinaryData = true
112
+ break
113
+ end
83
114
  }
84
115
 
116
+ if haveBinaryData then
117
+ # TODO Encode binary body data with base64.
118
+ # XXX Omit for now.
119
+ text = ""
120
+ end
121
+
85
122
  {
86
123
  size: getBodySize(body),
87
124
 
@@ -116,7 +153,7 @@ module Akita
116
153
  # for the CRLF on the blank line.
117
154
  headers.reduce(status_length + 2) { |accum, (k, v)|
118
155
  # Header-Name: header value<CR><LF>
119
- accum + k.length + 2 + v.length + 2
156
+ accum + k.length + 2 + v.to_s.length + 2
120
157
  }
121
158
  end
122
159
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Akita
4
4
  module HarLogger
5
- VERSION = "0.2.5"
5
+ VERSION = "0.2.9"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akita-har_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jed Liu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-12 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec