ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:51000] 2.7までで動いていたが3.0でエンコードのエラーになる
@ 2021-01-28 14:28 paptimusx
  2021-01-29 15:05 ` [ruby-dev:51001] 2.7までで動いていたが3.0でエンコードのエラーになる U.NAKAMURA
  0 siblings, 1 reply; 5+ messages in thread
From: paptimusx @ 2021-01-28 14:28 UTC (permalink / raw)
  To: ruby-dev

[-- Attachment #1: Type: text/plain, Size: 1157 bytes --]

Windows10  (64ビット,日本語環境,cp932)
2.7までで動いていたが3.0でエラーになるようになった
2.7,3.0 ともchocolatelyで入れたもの
エンコーディングの仕様が変わったのでしょうか

再現のための短いコードを添付します
$ ver
Microsoft Windows [Version 10.0.19041.746]

$ cat a.txt
入力データ

$ cat a.rb
#!/usr/bin/ruby
#; coding: cp932
files = ARGV

for file in files
  $stderr.print "[#{file}]\n"
  fin = open(file, 'r')
  title = ' '
  while s = fin.gets
    if /\%TITLE=(.*):(.*)/i =~ s # ←10行目
      title = $2
    end
  end
  fin.close
end

------------------------------------------------------------
× Ruby 3.0

$ ruby -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x64-mingw32]

$ ruby a.rb a.txt
[a.txt]
a.rb:10:in `block in <main>': invalid byte sequence in UTF-8 (ArgumentError)
        from a.rb:5:in `each'
        from a.rb:5:in `<main>'


------------------------------------------------------------
〇 Ruby2.7

$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]

$ ruby a.rb a.txt
[a.txt]

[-- Attachment #2: Type: text/html, Size: 1439 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-03 16:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28 14:28 [ruby-dev:51000] 2.7までで動いていたが3.0でエンコードのエラーになる paptimusx
2021-01-29 15:05 ` [ruby-dev:51001] 2.7までで動いていたが3.0でエンコードのエラーになる U.NAKAMURA
2021-02-03 15:01   ` [ruby-dev:51012] " paptimusx
2021-02-03 16:18     ` [ruby-dev:51013] " U.NAKAMURA
2021-02-03 16:43       ` [ruby-dev:51014] " paptimusx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).