Skip to content

Instantly share code, notes, and snippets.

@shyouhei
Created November 1, 2011 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shyouhei/1330056 to your computer and use it in GitHub Desktop.
Save shyouhei/1330056 to your computer and use it in GitHub Desktop.
Pathname's raising "invalid sequence"
# -*- coding: utf-8 -*-
require 'pathname'
s1 = File.dirname(__FILE__)
s2 = File.expand_path('ディレクトリ/ファイル', s1)
s3 = File.dirname(s2)
s4 = File.expand_path(s3)
p1 = Pathname(s2)
p2 = Pathname(s4)
p3 = p2.relative_path_from(p1)
zsh % ruby -v bug.rb
ruby 1.9.3p0 (2011-10-30 revision 33569) [x86_64-linux]
/lib/ruby/1.9.1/pathname.rb:45:in `=~': invalid byte sequence in UTF-8 (ArgumentError)
from /lib/ruby/1.9.1/pathname.rb:45:in `chop_basename'
from /lib/ruby/1.9.1/pathname.rb:101:in `cleanpath_aggressive'
from /lib/ruby/1.9.1/pathname.rb:89:in `cleanpath'
from /lib/ruby/1.9.1/pathname.rb:450:in `relative_path_from'
from bug.rb:10:in `<main>'
zsh: exit 1 ruby -v bug.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment