ruby-ole 1.2.11.6 → 1.2.11.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ == 1.2.11.7 / 2013-06-24
2
+
3
+ - Various encoding fixes to make tests pass on current rubies.
4
+ - Fix RangesIO#write behaviour when passed an encoded string (github #14,
5
+ romuloceccon).
6
+ - Fix Dirent#each_child attempting iteration on file children (github #13).
7
+ - Unused variable fixes to avoid warnings (github #12, kachick).
8
+
1
9
  == 1.2.11.6 / 2012-12-10
2
10
 
3
11
  - Fix breakage of writable IO stream detection on Windows (github #11).
data/lib/ole/ranges_io.rb CHANGED
@@ -195,6 +195,11 @@ class RangesIO
195
195
  end
196
196
 
197
197
  def write data
198
+ # duplicates object to avoid side effects for the caller, but do so only if
199
+ # encoding isn't already ASCII-8BIT (slight optimization)
200
+ if data.respond_to?(:encoding) and data.encoding != Encoding::ASCII_8BIT
201
+ data = data.dup.force_encoding(Encoding::ASCII_8BIT)
202
+ end
198
203
  return 0 if data.empty?
199
204
  data_pos = 0
200
205
  # if we don't have room, we can use the truncate hook to make more space.
@@ -50,6 +50,8 @@ module Ole # :nodoc:
50
50
  raise ArgumentError, 'unable to specify mode string with io object' if mode
51
51
  [false, arg]
52
52
  end
53
+ # force encoding, to avoid picking up source encoding with StringIO or files in text mode
54
+ @io.set_encoding Encoding::ASCII_8BIT if @io.respond_to?(:set_encoding)
53
55
  # do we have this file opened for writing? use mode when provided,
54
56
  # otherwise try no-op methods which will raise if read-only
55
57
  @writeable = begin
@@ -229,7 +231,6 @@ module Ole # :nodoc:
229
231
  # delete a lot of stuff, and free up trailing blocks, the file size never shrinks. this can
230
232
  # be fixed easily, add an io truncate
231
233
  @bbat.truncate!
232
- before = @io.size
233
234
  @io.truncate @bbat.block_size * (@bbat.length + 1)
234
235
  while true
235
236
  # get total bbat size. equivalent to @bbat.to_s.length, but for the factoring in of
@@ -832,7 +833,7 @@ module Ole # :nodoc:
832
833
  end
833
834
 
834
835
  def each_child(&block)
835
- @children.each(&block)
836
+ @children.each(&block) if dir?
836
837
  end
837
838
 
838
839
  # flattens the tree starting from here into +dirents+. note it modifies its argument.
@@ -76,8 +76,8 @@ module Ole
76
76
  # byte_order: 0xffe
77
77
  # windows_version: 0x00000a03 (win31 apparently)
78
78
  # marker: 0xffffffff
79
- compobj_version, byte_order, windows_version, marker, clsid =
80
- data.unpack("vvVVa#{Types::Clsid::SIZE}")
79
+ # compobj_version, byte_order, windows_version, marker, clsid =
80
+ # data.unpack("vvVVa#{Types::Clsid::SIZE}")
81
81
  strings = []
82
82
  i = 28
83
83
  while i < data.length
@@ -137,7 +137,7 @@ module Ole
137
137
 
138
138
  def method_missing name, *args, &block
139
139
  return super unless args.empty?
140
- pair = Types::PropertySet::PROPERTY_MAP[name.to_s] or return super
140
+ return super unless Types::PropertySet::PROPERTY_MAP[name.to_s]
141
141
  self[name]
142
142
  end
143
143
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Ole # :nodoc:
4
4
  class Storage
5
- VERSION = '1.2.11.6'
5
+ VERSION = '1.2.11.7'
6
6
  end
7
7
  end
8
8
 
@@ -68,7 +68,7 @@ module Ole
68
68
  end
69
69
 
70
70
  module Constants
71
- DATA.each { |guid, (name, map)| const_set name, guid }
71
+ DATA.each { |guid, (name, _)| const_set name, guid }
72
72
  end
73
73
 
74
74
  include Constants
@@ -1,4 +1,5 @@
1
1
  #! /usr/bin/ruby
2
+ # encoding: ASCII-8BIT
2
3
 
3
4
  #
4
5
  # = NOTE
@@ -564,10 +565,9 @@ class OleFsFileStatTest < Test::Unit::TestCase
564
565
  # an additional test i added for coverage. i've tried to make the inspect
565
566
  # string on the ole stat match that of the regular one.
566
567
  def test_inspect
567
- expect = '#<Ole::Storage::FileClass::Stat ino=0, uid=0, size=72, rdev=0, nlink=1, dev=0, blocks=2, gid=0, ftype=file, blksize=64>'
568
- # normalize them, as instance_variables order is undefined
568
+ # normalize, as instance_variables order is undefined
569
569
  normalize = proc { |s| s[/ (.*)>$/, 1].split(', ').sort.join(', ') }
570
- assert_equal normalize[expect], normalize[@ole.file.stat('file1').inspect]
570
+ assert_match %r{blocks=2.*ftype=file.*size=72}, normalize[@ole.file.stat('file1').inspect]
571
571
  end
572
572
  end
573
573
 
@@ -594,20 +594,24 @@ class OleFsFileMutatingTest < Test::Unit::TestCase
594
594
  Ole::Storage.open(@io) {
595
595
  |zf|
596
596
 
597
+ blockCalled = nil
597
598
  zf.file.open("test_open_write_entry", "w") {
598
599
  |f|
599
600
  blockCalled = true
600
601
  f.write "This is what I'm writing"
601
602
  }
603
+ assert(blockCalled)
602
604
  assert_equal("This is what I'm writing",
603
605
  zf.file.read("test_open_write_entry"))
604
606
 
607
+ blockCalled = nil
605
608
  # Test with existing entry
606
609
  zf.file.open("file1", "w") {
607
610
  |f|
608
611
  blockCalled = true
609
612
  f.write "This is what I'm writing too"
610
613
  }
614
+ assert(blockCalled)
611
615
  assert_equal("This is what I'm writing too",
612
616
  zf.file.read("file1"))
613
617
  }
@@ -902,6 +906,24 @@ class OleUnicodeTest < Test::Unit::TestCase
902
906
  end
903
907
  end
904
908
  end
909
+
910
+ def test_write_utf8_string
911
+ programmer = "programa\xC3\xA7\xC3\xA3o "
912
+ programmer.force_encoding Encoding::UTF_8 if programmer.respond_to? :encoding
913
+ Ole::Storage.open @io do |ole|
914
+ ole.file.open '1', 'w' do |writer|
915
+ writer.write(programmer)
916
+ writer.write('ruby')
917
+ end
918
+ end
919
+ Ole::Storage.open @io do |ole|
920
+ ole.file.open '1', 'r' do |reader|
921
+ s = reader.read
922
+ s = s.force_encoding('UTF-8') if s.respond_to?(:encoding)
923
+ assert_equal(programmer + 'ruby', s)
924
+ end
925
+ end
926
+ end
905
927
  end
906
928
 
907
929
  # Copyright (C) 2002, 2003 Thomas Sondergaard
data/test/test_storage.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #! /usr/bin/ruby
2
+ # coding: utf-8
2
3
 
3
4
  $: << File.dirname(__FILE__) + '/../lib'
4
5
  #require 'rubygems'
data/test/test_types.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #! /usr/bin/ruby
2
+ # encoding: ASCII-8BIT
2
3
 
3
4
  $: << File.dirname(__FILE__) + '/../lib'
4
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-ole
3
3
  version: !ruby/object:Gem::Version
4
- hash: 111
4
+ hash: 109
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
9
  - 11
10
- - 6
11
- version: 1.2.11.6
10
+ - 7
11
+ version: 1.2.11.7
12
12
  platform: ruby
13
13
  authors:
14
14
  - Charles Lowe
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-12-10 00:00:00 +11:00
19
+ date: 2013-06-24 00:00:00 +10:00
20
20
  default_executable:
21
21
  dependencies: []
22
22