Skip to content

Commit

Permalink
Tell Ruby 2.0 to use US-ASCII encoding for vcard.rb
Browse files Browse the repository at this point in the history
This fixes sam-github#5. Ruby 2.0 assumes UTF-8 sourcefile encoding.
  • Loading branch information
mikezter committed Jul 26, 2013
1 parent c945e18 commit 3915b69
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/vpim/vcard.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: US-ASCII

=begin
Copyright (C) 2008 Sam Roberts
Expand Down

1 comment on commit 3915b69

@henrycatalinismith
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run the vcard tests with this under Ruby 2.0.0, the "invalid multibyte escape" error does go away, but I get the following error instead.

$ ruby -Ilib test/test_vcard.rb 
Run options: 

# Running tests:

[15/28] TestVcard#test_modify_name = 0.00 s                                
  1) Failure:
test_modify_name(TestVcard) [test/test_vcard.rb:693]:
[TypeError] exception expected, not
Class: <RuntimeError>
Message: <"can't modify frozen Vpim::Vcard::Name">
---Backtrace---
test/test_vcard.rb:694:in `block in test_modify_name'
/Users/h2s/.rbenv/versions/2.0.0-dev/lib/ruby/2.0.0/minitest/unit.rb:370:in `assert_raises'
test/test_vcard.rb:693:in `test_modify_name'
[truncated enormous unit test stack trace]
---------------

[23/28] TestVcard#test_utf_heuristics = 0.00 s             
  2) Error:
test_utf_heuristics(TestVcard):
Encoding::CompatibilityError: incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string) "BEGIN:VCARD\nN:name\nEND:VCARD\n"
    /Users/h2s/src/vpim/lib/vpim/vcard.rb:675:in `==='
    /Users/h2s/src/vpim/lib/vpim/vcard.rb:675:in `decode'
    test/test_vcard.rb:831:in `utf_name_test'
    test/test_vcard.rb:849:in `test_utf_heuristics'
    /Users/h2s/.rbenv/versions/2.0.0-dev/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'
    /Users/h2s/.rbenv/versions/2.0.0-dev/lib/ruby/2.0.0/test/unit/testcase.rb:17:in `run'
    /Users/h2s/.rbenv/versions/2.0.0-dev/lib/ruby/2.0.0/minitest/unit.rb:919:in `block in _run_suite'
    [truncated enormous unit test stack trace]

Finished tests in 0.251778s, 111.2091 tests/s, 615.6217 assertions/s.
28 tests, 155 assertions, 1 failures, 1 errors, 0 skips

ruby -v: ruby 2.0.0p255 (2013-07-07 revision 41812) [x86_64-darwin12.4.1]

It seems that this commit causes vpim to break on any UTF-8 input, because Ruby barfs when you try to put UTF-8 strings through a regex literal from a file marked as # encoding: US-ASCII.

Please sign in to comment.