Skip to content

Commit 63a7be2

Browse files
Force UTF-8 encoding of strings (#5)
* 🚧 Force utf-8 encoding of all strings in log items * 📦 Bump gem version
1 parent 10c166e commit 63a7be2

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10-
## [1.0.0] - 2021-02-11
10+
## [0.1.0] - 2021-02-11
1111

1212
- The first version of the client.
13+
14+
## [0.1.2] - 2021-04-22
15+
16+
- Fixed string encoding.

lib/logtail/log_devices/http.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,20 @@ def build_request(msgs)
201201
req['Authorization'] = authorization_payload
202202
req['Content-Type'] = CONTENT_TYPE
203203
req['User-Agent'] = USER_AGENT
204-
req.body = msgs.to_msgpack
204+
req.body = msgs.map { |msg| force_utf8_encoding(msg.to_hash) }.to_msgpack
205205
req
206206
end
207207

208+
def force_utf8_encoding(data)
209+
if data.respond_to?(:force_encoding)
210+
data.dup.force_encoding('UTF-8')
211+
elsif data.respond_to?(:transform_values)
212+
data.transform_values { |val| force_utf8_encoding(val) }
213+
else
214+
data
215+
end
216+
end
217+
208218
# Flushes the message buffer asynchronously. The reason we provide this
209219
# method is because the message buffer limit is constricted by the
210220
# Logtail API. The application limit is multiples of the buffer limit,

lib/logtail/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Logtail
2-
VERSION = "0.1.1"
2+
VERSION = "0.1.2"
33
end

0 commit comments

Comments
 (0)