diff --git a/lib/log-courier/client.rb b/lib/log-courier/client.rb index 7e570f56..1dbdf0da 100644 --- a/lib/log-courier/client.rb +++ b/lib/log-courier/client.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # This file is a modification of code from Logstash Forwarder. diff --git a/lib/log-courier/client_tls.rb b/lib/log-courier/client_tls.rb index 33ce5225..020e0d68 100644 --- a/lib/log-courier/client_tls.rb +++ b/lib/log-courier/client_tls.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # This file is a modification of code from Logstash Forwarder. diff --git a/lib/log-courier/server.rb b/lib/log-courier/server.rb index a34f9633..7c25a403 100644 --- a/lib/log-courier/server.rb +++ b/lib/log-courier/server.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # This file is a modification of code from Logstash Forwarder. @@ -144,8 +146,15 @@ def process_jdat(message, comm, event_queue) raise ProtocolError end - # Extract message, and force UTF-8 to ensure we don't break anything, replacing invalid sequences - data = message[p...p + length].encode('utf-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '?').force_encoding('UTF-8') + # Extract message + data = message[p...p + length].force_encoding('utf-8') + + # Ensure valid encoding + unless data.valid_encoding? + data.chars.map do |c| + c.valid_encoding? ? c : "\xEF\xBF\xBD" + end + end p += length # Decode the JSON diff --git a/lib/log-courier/server_tcp.rb b/lib/log-courier/server_tcp.rb index 256594a7..9be382d4 100644 --- a/lib/log-courier/server_tcp.rb +++ b/lib/log-courier/server_tcp.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # This file is a modification of code from Logstash Forwarder. diff --git a/lib/log-courier/server_zmq.rb b/lib/log-courier/server_zmq.rb index 71c848e7..8cbf57a3 100644 --- a/lib/log-courier/server_zmq.rb +++ b/lib/log-courier/server_zmq.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/courier_spec.rb b/spec/courier_spec.rb index 345f5788..7a14d756 100644 --- a/spec/courier_spec.rb +++ b/spec/courier_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/gem_spec.rb b/spec/gem_spec.rb index 54947d26..b7e5b1fd 100644 --- a/spec/gem_spec.rb +++ b/spec/gem_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/lib/common.rb b/spec/lib/common.rb index bc2b5d29..4b5d3f87 100644 --- a/spec/lib/common.rb +++ b/spec/lib/common.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/lib/helpers/common.rb b/spec/lib/helpers/common.rb index e0aeb32c..9ec6c3e0 100644 --- a/spec/lib/helpers/common.rb +++ b/spec/lib/helpers/common.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/lib/helpers/log-courier.rb b/spec/lib/helpers/log-courier.rb index 304afdaa..80a89ba5 100644 --- a/spec/lib/helpers/log-courier.rb +++ b/spec/lib/helpers/log-courier.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/lib/logfile.rb b/spec/lib/logfile.rb index c79360fa..f0ce7951 100644 --- a/spec/lib/logfile.rb +++ b/spec/lib/logfile.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/lib/logfile/multiline.rb b/spec/lib/logfile/multiline.rb index 65a68748..5c230426 100644 --- a/spec/lib/logfile/multiline.rb +++ b/spec/lib/logfile/multiline.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/multiline_spec.rb b/spec/multiline_spec.rb index 6116d295..7818df33 100644 --- a/spec/multiline_spec.rb +++ b/spec/multiline_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/plainzmq_spec.rb b/spec/plainzmq_spec.rb index 8ef783dc..edc6f72c 100644 --- a/spec/plainzmq_spec.rb +++ b/spec/plainzmq_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/tcp_spec.rb b/spec/tcp_spec.rb index ae628fc8..ba218209 100644 --- a/spec/tcp_spec.rb +++ b/spec/tcp_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/zmq_spec.rb b/spec/zmq_spec.rb index 24485ad6..2c68748a 100644 --- a/spec/zmq_spec.rb +++ b/spec/zmq_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + # Copyright 2014 Jason Woods. # # Licensed under the Apache License, Version 2.0 (the "License");