Backport #7911

特定の条件の時に、File.fnmatchに渡すpatternがUS-ASCII、pathがUTF-8だとInvalid sequenceでエラーが出る

Added by Shunsuke Shimizu over 2 years ago. Updated over 2 years ago.

[ruby-dev:47068]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

Description

=begin
# coding: utf-8
File.fnmatch('a'.encode('US-ASCII'), 'あ', File::FNM_CASEFOLD)

というコードを実行した際に、

test-fnmatch.rb:2:in fnmatch': invalid byte sequence in US-ASCII (ArgumentError)
from test-fnmatch.rb:2:in
'

というエラーが発生します。UTF-8文字列である'あ'を、'a'と同じUS-ASCIIだとしてcase insenstiveなマッチのためにupcaseを試みているのがエラー原因と思われます。

添付のパッチで動作するようになることを確認しました。
=end

fix-fnmatch.patch Magnifier (967 Bytes) Shunsuke Shimizu, 02/22/2013 07:00 PM

Associated revisions

Revision 39413
Added by Nobuyoshi Nakada over 2 years ago

dir.c: encoding check

  • dir.c (file_s_fnmatch, fnmatch_brace): encoding-incompatible pattern and string do not match, instead of exception. [Bug #7911]

Revision 39662
Added by Tomoyuki Chikanaga over 2 years ago

merge revision(s) 39413: [Backport #7911]

* dir.c (file_s_fnmatch, fnmatch_brace): encoding-incompatible pattern
  and string do not match, instead of exception.  
  [Bug #7911]

History

#1 Updated by Koichi Sasada over 2 years ago

  • Category set to M17N
  • Assignee set to Yui NARUSE
  • Target version set to 2.1.0

naruse さんに 2.1.0 として振りますが、2.0.0 に必要かどうかはご判断下さい。

#2 Updated by Nobuyoshi Nakada over 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39413.
Shunsuke, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


dir.c: encoding check

  • dir.c (file_s_fnmatch, fnmatch_brace): encoding-incompatible pattern and string do not match, instead of exception. [Bug #7911]

#3 Updated by Nobuyoshi Nakada over 2 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby trunk to Backport200
  • Category deleted (M17N)
  • Status changed from Closed to Assigned
  • Assignee changed from Yui NARUSE to Yusuke Endoh
  • Target version deleted (2.1.0)

#4 Updated by Tomoyuki Chikanaga over 2 years ago

  • Assignee changed from Yusuke Endoh to Tomoyuki Chikanaga

#5 Updated by Tomoyuki Chikanaga over 2 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r39662.
Shunsuke, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 39413: [Backport #7911]

* dir.c (file_s_fnmatch, fnmatch_brace): encoding-incompatible pattern
  and string do not match, instead of exception.  
  [Bug #7911]

Also available in: Atom PDF