diff --git a/lib/lotus/utils/escape.rb b/lib/lotus/utils/escape.rb
index <HASH>..<HASH> 100644
--- a/lib/lotus/utils/escape.rb
+++ b/lib/lotus/utils/escape.rb
@@ -528,9 +528,10 @@ module Lotus
       # @since 0.4.0
       # @api private
       def self.encode(input)
-        input.to_s.encode(Encoding::UTF_8)
+        return '' if input.nil?
+        input.encode(Encoding::UTF_8)
       rescue Encoding::UndefinedConversionError
-        input.to_s.force_encoding(Encoding::UTF_8)
+        input.dup.force_encoding(Encoding::UTF_8)
       end
 
       # Encode the given UTF-8 char.
diff --git a/test/escape_test.rb b/test/escape_test.rb
index <HASH>..<HASH> 100644
--- a/test/escape_test.rb
+++ b/test/escape_test.rb
@@ -105,8 +105,14 @@ describe Lotus::Utils::Escape do
     it "escapes 'тест'" do
       skip "There is no ASCII-8BIT encoding" unless Encoding.name_list.include?('ASCII-8BIT')
 
-      result = mod.html('тест'.force_encoding('ASCII-8BIT'))
+      string   = 'тест'.force_encoding('ASCII-8BIT')
+      encoding = string.encoding
+
+      result = mod.html(string)
       result.must_equal 'тест'
+      result.encoding.must_equal Encoding::UTF_8
+
+      string.encoding.must_equal encoding
     end
   end
Ensure immutability for encoded strings which failed the conversion Ref #<I>