archive-zip 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd99221a399fb578d4b75ae55e330e156d1f3d56
4
- data.tar.gz: e76e2ad7ff8f5ff1c545d90287065e41850e35a3
3
+ metadata.gz: 9138f623736687f7bffedd8be706a604ef986143
4
+ data.tar.gz: 6098fe76a711d2a74aa6a69918eb507fd6de5654
5
5
  SHA512:
6
- metadata.gz: 12fce07dfaa1ad74b68b41ec373c2a17101dff73aeed2500874ab2e112933086311881fe5ea15f46a6db3b73f6a3d7c7cfe8c7772bccbee4e7ae070ca4314db1
7
- data.tar.gz: e5941deb576206a4b6d0253b61d5d3b7cdf10c06ad716a4ff0fc4bd1fbc9926d3ff1b2265a04680382ed9f2f1209e89af7cbd6d6053d14cb8f4f3380c702bf8c
6
+ metadata.gz: 319cd9c5e8882d05032abb80e8f6cd6cab9459226eb95be0458caaf950239d1d2d03495d3338af12f1c950fd68fd7e76d33f74af322de520ad64a066b03831f0
7
+ data.tar.gz: 6763e8e864211d2277d8bcd6a3cec53a2c51a7a4b84f004c4d5a9b4f740cafc714b145537a7fe8faa0f73b90ac398962fbcf390ef30a51f126444ea3a47145d8
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2015 Jeremy Bopp
3
+ Copyright (c) 2016 Jeremy Bopp
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/NEWS.md CHANGED
@@ -6,6 +6,12 @@ detailed information is available in the rest of the documentation.
6
6
  **NOTE:** Date stamps in the following entries are in YYYY/MM/DD format.
7
7
 
8
8
 
9
+ ## v0.9.0 (2016/12/18)
10
+
11
+ ### Fixes
12
+
13
+ * Initialize DOSTime correctly when not given a struct to parse.
14
+
9
15
  ## v0.8.0 (2015/01/05)
10
16
 
11
17
  ### Fixes
data/README.md CHANGED
@@ -228,7 +228,7 @@ be more easily accepted if they are consistent with the rest of the code.
228
228
  ```
229
229
  (The MIT License)
230
230
 
231
- Copyright (c) 2015 Jeremy Bopp
231
+ Copyright (c) 2016 Jeremy Bopp
232
232
 
233
233
  Permission is hereby granted, free of charge, to any person obtaining
234
234
  a copy of this software and associated documentation files (the
@@ -45,7 +45,7 @@ module Archive
45
45
  def initialize(dos_time = nil)
46
46
  case dos_time
47
47
  when nil
48
- @dos_time = Time.now.to_dos_time.dos_time
48
+ @dos_time = Time.now.to_dos_time.to_i
49
49
  when Integer
50
50
  @dos_time = dos_time
51
51
  else
@@ -54,6 +54,8 @@ module Archive
54
54
  end
55
55
  @dos_time = dos_time.unpack('V')[0]
56
56
  end
57
+
58
+ validate
57
59
  end
58
60
 
59
61
  # Returns -1 if _other_ is a time earlier than this one, 0 if _other_ is the
@@ -86,5 +88,32 @@ module Archive
86
88
  year = ((0b1111111 << 25 & @dos_time) >> 25) + 1980
87
89
  return Time.local(year, month, day, hour, minute, second)
88
90
  end
91
+
92
+ private
93
+
94
+ def validate
95
+ second = (0b11111 & @dos_time)
96
+ minute = (0b111111 << 5 & @dos_time) >> 5
97
+ hour = (0b11111 << 11 & @dos_time) >> 11
98
+ day = (0b11111 << 16 & @dos_time) >> 16
99
+ month = (0b1111 << 21 & @dos_time) >> 21
100
+ year = (0b1111111 << 25 & @dos_time) >> 25
101
+
102
+ if second > 29
103
+ raise ArgumentError, 'second must not be greater than 29'
104
+ elsif minute > 59
105
+ raise ArgumentError, 'minute must not be greater than 59'
106
+ elsif hour > 24
107
+ raise ArgumentError, 'hour must not be greater than 24'
108
+ elsif day < 1
109
+ raise ArgumentError, 'day must not be less than 1'
110
+ elsif month < 1
111
+ raise ArgumentError, 'month must not be less than 1'
112
+ elsif month > 12
113
+ raise ArgumentError, 'month must not be greater than 12'
114
+ elsif year > 119
115
+ raise ArgumentError, 'year must not be greater than 119'
116
+ end
117
+ end
89
118
  end
90
119
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Archive; class Zip
4
4
  # The current version of this gem.
5
- VERSION = '0.8.0'
5
+ VERSION = '0.9.0'
6
6
  end; end
@@ -0,0 +1,113 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'minitest/autorun'
4
+
5
+ require 'archive/support/time'
6
+
7
+ describe 'Archive::DOSTime.new' do
8
+ let(:epoc) { 0b0000000_0001_00001_00000_000000_00000 }
9
+ let(:end_times) { 0b1110111_1100_11111_11000_111011_11101 }
10
+
11
+ it 'uses the current time when no structure is given' do
12
+ now = Time.now.localtime
13
+ dos_time = Archive::DOSTime.new.to_time
14
+
15
+ now.year.must_be_close_to(dos_time.year, 1)
16
+ now.month.must_be_close_to(dos_time.month, 1)
17
+ now.day.must_be_close_to(dos_time.day, 1)
18
+ now.hour.must_be_close_to(dos_time.hour, 1)
19
+ now.min.must_be_close_to(dos_time.min, 1)
20
+ now.sec.must_be_close_to(dos_time.sec, 3)
21
+ end
22
+
23
+ it 'accepts valid Integer structures' do
24
+ Archive::DOSTime.new(epoc)
25
+ Archive::DOSTime.new(end_times)
26
+ end
27
+
28
+ it 'accepts valid String structures' do
29
+ Archive::DOSTime.new([epoc].pack('V'))
30
+ Archive::DOSTime.new([end_times].pack('V'))
31
+ end
32
+
33
+ it 'rejects invalid Integer structures' do
34
+ # Second must not be greater than 29.
35
+ proc {
36
+ Archive::DOSTime.new(epoc | 0b0000000_0000_00000_00000_000000_11110)
37
+ }.must_raise(ArgumentError)
38
+
39
+ # Minute must not be greater than 59.
40
+ proc {
41
+ Archive::DOSTime.new(epoc | 0b0000000_0000_00000_00000_111100_00000)
42
+ }.must_raise(ArgumentError)
43
+
44
+ # Hour must not be greater than 24.
45
+ proc {
46
+ Archive::DOSTime.new(epoc | 0b0000000_0000_00000_11001_000000_00000)
47
+ }.must_raise(ArgumentError)
48
+
49
+ # Day must not be zero.
50
+ proc {
51
+ Archive::DOSTime.new(epoc & 0b1111111_1111_00000_11111_111111_11111)
52
+ }.must_raise(ArgumentError)
53
+
54
+ # Month must not be zero.
55
+ proc {
56
+ Archive::DOSTime.new(epoc & 0b1111111_0000_11111_11111_111111_11111)
57
+ }.must_raise(ArgumentError)
58
+
59
+ # Month must not be greater than 12.
60
+ proc {
61
+ Archive::DOSTime.new(epoc | 0b0000000_1101_00000_00000_000000_00000)
62
+ }.must_raise(ArgumentError)
63
+
64
+ # Year must not be greater than 119.
65
+ proc {
66
+ Archive::DOSTime.new(epoc | 0b1111000_0000_00000_00000_000000_00000)
67
+ }.must_raise(ArgumentError)
68
+ end
69
+
70
+ it 'rejects invalid String structures' do
71
+ # Second must not be greater than 29.
72
+ proc {
73
+ packed = [epoc | 0b0000000_0000_00000_00000_000000_11110].pack('V')
74
+ Archive::DOSTime.new(packed)
75
+ }.must_raise(ArgumentError)
76
+
77
+ # Minute must not be greater than 59.
78
+ proc {
79
+ packed = [epoc | 0b0000000_0000_00000_00000_111100_00000].pack('V')
80
+ Archive::DOSTime.new(packed)
81
+ }.must_raise(ArgumentError)
82
+
83
+ # Hour must not be greater than 24.
84
+ proc {
85
+ packed = [epoc | 0b0000000_0000_00000_11001_000000_00000].pack('V')
86
+ Archive::DOSTime.new(packed)
87
+ }.must_raise(ArgumentError)
88
+
89
+ # Day must not be zero.
90
+ proc {
91
+ packed = [epoc & 0b1111111_1111_00000_11111_111111_11111].pack('V')
92
+ Archive::DOSTime.new(packed)
93
+ }.must_raise(ArgumentError)
94
+
95
+ # Month must not be zero.
96
+ proc {
97
+ packed = [epoc & 0b1111111_0000_11111_11111_111111_11111].pack('V')
98
+ Archive::DOSTime.new(packed)
99
+ }.must_raise(ArgumentError)
100
+
101
+ # Month must not be greater than 12.
102
+ proc {
103
+ packed = [epoc | 0b0000000_1101_00000_00000_000000_00000].pack('V')
104
+ Archive::DOSTime.new(packed)
105
+ }.must_raise(ArgumentError)
106
+
107
+ # Year must not be greater than 119.
108
+ proc {
109
+ packed = [epoc | 0b1111000_0000_00000_00000_000000_00000].pack('V')
110
+ Archive::DOSTime.new(packed)
111
+ }.must_raise(ArgumentError)
112
+ end
113
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archive-zip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Bopp
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-06 00:00:00.000000000 Z
12
+ date: 2016-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: io-like
@@ -147,6 +147,7 @@ files:
147
147
  - lib/archive/zip/extra_field/raw.rb
148
148
  - lib/archive/zip/extra_field/unix.rb
149
149
  - lib/archive/zip/version.rb
150
+ - spec/archive/dos_time_spec.rb
150
151
  - spec/archive/zip/archive_spec.rb
151
152
  - spec/archive/zip/codec/deflate/compress/checksum_spec.rb
152
153
  - spec/archive/zip/codec/deflate/compress/close_spec.rb
@@ -273,6 +274,7 @@ signing_key:
273
274
  specification_version: 4
274
275
  summary: Simple, extensible, pure Ruby ZIP archive support.
275
276
  test_files:
277
+ - spec/archive/dos_time_spec.rb
276
278
  - spec/archive/zip/archive_spec.rb
277
279
  - spec/archive/zip/codec/deflate/compress/checksum_spec.rb
278
280
  - spec/archive/zip/codec/deflate/compress/close_spec.rb