Project

General

Profile

Bug #9016 » encoding-lying-reduced.rb

renatosilva (Renato Silva), 10/14/2013 06:57 PM

 
1
# Encoding: UTF-8
2

    
3
if ARGV[0] == nil or ARGV[0].encoding != Encoding::CP850
4
    puts "Please run me from cmd.exe after \"chcp 850\", and pass me"
5
    puts "a lowercase a-tilde (http://en.wikipedia.org/wiki/%C3%83)."
6
    exit
7
end
8

    
9
puts "Encoding of argument is reported as #{ARGV[0].encoding} and as #{ARGV[0].valid_encoding? ? "valid" : "invalid"}."
10
puts "Let us inspect the a-tilde argument: #{ARGV[0].dump}"
11
puts "Let us inspect the a-tilde from UTF-8 source code transcoded into CP850: #{"ã".encode("CP850").dump}"
12
puts "Let us inspect the a-tilde from UTF-8 source code transcoded into ISO-8859-1: #{"ã".encode("ISO-8859-1").dump}"
13
puts "RESULT: as you can see, the argument looks like an ISO-8859-1 string, but reports its encoding as CP850."