ndr_import 8.4.0 → 8.5.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +3 -0
- data/code_safety.yml +34 -22
- data/gemfiles/Gemfile.rails50 +3 -0
- data/gemfiles/Gemfile.rails51 +3 -0
- data/gemfiles/Gemfile.rails52 +3 -0
- data/lib/ndr_import/file/docx.rb +25 -3
- data/lib/ndr_import/file/excel.rb +8 -1
- data/lib/ndr_import/file/office_file_helper.rb +20 -0
- data/lib/ndr_import/table.rb +2 -2
- data/lib/ndr_import/universal_importer_helper.rb +1 -0
- data/lib/ndr_import/version.rb +1 -1
- data/ndr_import.gemspec +2 -1
- data/test/file/delimited_test.rb +2 -2
- data/test/file/docx_test.rb +14 -0
- data/test/file/excel_test.rb +10 -0
- data/test/helpers/file/delimited_test.rb +2 -2
- data/test/non_tabular/table_test.rb +2 -1
- data/test/resources/password_protected_hello_world.docx +0 -0
- data/test/resources/password_protected_sample_xlsx.xlsx +0 -0
- data/test/table_test.rb +4 -3
- data/test/test_helper.rb +7 -0
- metadata +26 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9190c1ebeb14ff9e86f5fc64510f1bd4a0f6c28290727650b80b975cbac85624
|
|
4
|
+
data.tar.gz: f94476c5853d351c9e12542a00adba3ce708bf4ba7b37c16d1589ecd710a3342
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b8978a404f15132428414b8809b6fb7a98649fa44dde1c339b4df7894203913048a3aae6f69d5613779e5e26dcfb525315751c30d88c8a36870110e55ccd7ccb
|
|
7
|
+
data.tar.gz: dd3dcb71aa46792a49327b95b513f53279e74ae9b52cc2024802f9717d9149f31d1931bf707686840bc9f2301703c672bf14d02da737c39ed93333c8d23cff13
|
data/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
*no unreleased changes*
|
|
3
3
|
|
|
4
|
+
## 8.5.0 / 2019-05-01
|
|
5
|
+
### Added
|
|
6
|
+
* Allow encypted docx/xlsx files to be read using `:file_password` option (#37)
|
|
7
|
+
|
|
4
8
|
## 8.4.0 / 2019-03-15
|
|
9
|
+
### Added
|
|
5
10
|
* Added ability to extract and transform PDF form data (#24)
|
|
6
11
|
|
|
7
12
|
## 8.3.0 / 2019-03-04
|
data/Gemfile
CHANGED
data/code_safety.yml
CHANGED
|
@@ -15,19 +15,19 @@ file safety:
|
|
|
15
15
|
".travis.yml":
|
|
16
16
|
comments:
|
|
17
17
|
reviewed_by: josh.pencheon
|
|
18
|
-
safe_revision:
|
|
18
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
19
19
|
CHANGELOG.md:
|
|
20
20
|
comments:
|
|
21
21
|
reviewed_by: josh.pencheon
|
|
22
|
-
safe_revision:
|
|
22
|
+
safe_revision: da7a850cb2abe53b7c0d4eaf4950634209999b67
|
|
23
23
|
CODE_OF_CONDUCT.md:
|
|
24
24
|
comments:
|
|
25
25
|
reviewed_by: timgentry
|
|
26
26
|
safe_revision: 5d185a0aeba6a9cd2ff5e59efadcaeec9be45d8b
|
|
27
27
|
Gemfile:
|
|
28
28
|
comments:
|
|
29
|
-
reviewed_by:
|
|
30
|
-
safe_revision:
|
|
29
|
+
reviewed_by: josh.pencheon
|
|
30
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
31
31
|
Guardfile:
|
|
32
32
|
comments:
|
|
33
33
|
reviewed_by: timgentry
|
|
@@ -47,15 +47,15 @@ file safety:
|
|
|
47
47
|
gemfiles/Gemfile.rails50:
|
|
48
48
|
comments:
|
|
49
49
|
reviewed_by: josh.pencheon
|
|
50
|
-
safe_revision:
|
|
50
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
51
51
|
gemfiles/Gemfile.rails51:
|
|
52
52
|
comments:
|
|
53
53
|
reviewed_by: josh.pencheon
|
|
54
|
-
safe_revision:
|
|
54
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
55
55
|
gemfiles/Gemfile.rails52:
|
|
56
56
|
comments:
|
|
57
57
|
reviewed_by: josh.pencheon
|
|
58
|
-
safe_revision:
|
|
58
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
59
59
|
lib/ndr_import.rb:
|
|
60
60
|
comments:
|
|
61
61
|
reviewed_by: josh.pencheon
|
|
@@ -87,11 +87,15 @@ file safety:
|
|
|
87
87
|
lib/ndr_import/file/docx.rb:
|
|
88
88
|
comments:
|
|
89
89
|
reviewed_by: josh.pencheon
|
|
90
|
-
safe_revision:
|
|
90
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
91
91
|
lib/ndr_import/file/excel.rb:
|
|
92
92
|
comments:
|
|
93
|
-
reviewed_by:
|
|
94
|
-
safe_revision:
|
|
93
|
+
reviewed_by: josh.pencheon
|
|
94
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
95
|
+
lib/ndr_import/file/office_file_helper.rb:
|
|
96
|
+
comments:
|
|
97
|
+
reviewed_by: josh.pencheon
|
|
98
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
95
99
|
lib/ndr_import/file/pdf.rb:
|
|
96
100
|
comments:
|
|
97
101
|
reviewed_by: timgentry
|
|
@@ -199,11 +203,11 @@ file safety:
|
|
|
199
203
|
lib/ndr_import/table.rb:
|
|
200
204
|
comments: uses File.basename
|
|
201
205
|
reviewed_by: josh.pencheon
|
|
202
|
-
safe_revision:
|
|
206
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
203
207
|
lib/ndr_import/universal_importer_helper.rb:
|
|
204
208
|
comments:
|
|
205
209
|
reviewed_by: josh.pencheon
|
|
206
|
-
safe_revision:
|
|
210
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
207
211
|
lib/ndr_import/unmapped_data_error.rb:
|
|
208
212
|
comments:
|
|
209
213
|
reviewed_by: josh.pencheon
|
|
@@ -211,7 +215,7 @@ file safety:
|
|
|
211
215
|
lib/ndr_import/version.rb:
|
|
212
216
|
comments: another check?
|
|
213
217
|
reviewed_by: josh.pencheon
|
|
214
|
-
safe_revision:
|
|
218
|
+
safe_revision: da7a850cb2abe53b7c0d4eaf4950634209999b67
|
|
215
219
|
lib/ndr_import/xml/table.rb:
|
|
216
220
|
comments:
|
|
217
221
|
reviewed_by: josh.pencheon
|
|
@@ -219,7 +223,7 @@ file safety:
|
|
|
219
223
|
ndr_import.gemspec:
|
|
220
224
|
comments:
|
|
221
225
|
reviewed_by: josh.pencheon
|
|
222
|
-
safe_revision:
|
|
226
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
223
227
|
test/file/acro_form_test.rb:
|
|
224
228
|
comments:
|
|
225
229
|
reviewed_by: josh.pencheon
|
|
@@ -231,15 +235,15 @@ file safety:
|
|
|
231
235
|
test/file/delimited_test.rb:
|
|
232
236
|
comments:
|
|
233
237
|
reviewed_by: josh.pencheon
|
|
234
|
-
safe_revision:
|
|
238
|
+
safe_revision: 93ccee82fc2165d1ca2d9b03d146ae03e769ea96
|
|
235
239
|
test/file/docx_test.rb:
|
|
236
240
|
comments:
|
|
237
241
|
reviewed_by: josh.pencheon
|
|
238
|
-
safe_revision:
|
|
242
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
239
243
|
test/file/excel_test.rb:
|
|
240
244
|
comments:
|
|
241
|
-
reviewed_by:
|
|
242
|
-
safe_revision:
|
|
245
|
+
reviewed_by: josh.pencheon
|
|
246
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
243
247
|
test/file/pdf_test.rb:
|
|
244
248
|
comments:
|
|
245
249
|
reviewed_by: josh.pencheon
|
|
@@ -275,7 +279,7 @@ file safety:
|
|
|
275
279
|
test/helpers/file/delimited_test.rb:
|
|
276
280
|
comments:
|
|
277
281
|
reviewed_by: josh.pencheon
|
|
278
|
-
safe_revision:
|
|
282
|
+
safe_revision: 93ccee82fc2165d1ca2d9b03d146ae03e769ea96
|
|
279
283
|
test/helpers/file/excel_test.rb:
|
|
280
284
|
comments:
|
|
281
285
|
reviewed_by: joshpencheon
|
|
@@ -307,7 +311,7 @@ file safety:
|
|
|
307
311
|
test/non_tabular/table_test.rb:
|
|
308
312
|
comments:
|
|
309
313
|
reviewed_by: josh.pencheon
|
|
310
|
-
safe_revision:
|
|
314
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
311
315
|
test/non_tabular_file_helper_test.rb:
|
|
312
316
|
comments:
|
|
313
317
|
reviewed_by: timgentry
|
|
@@ -440,6 +444,14 @@ file safety:
|
|
|
440
444
|
comments:
|
|
441
445
|
reviewed_by: josh.pencheon
|
|
442
446
|
safe_revision: 902f5326d85372d9632de9869d6f56fc02b83a10
|
|
447
|
+
test/resources/password_protected_hello_world.docx:
|
|
448
|
+
comments:
|
|
449
|
+
reviewed_by: josh.pencheon
|
|
450
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
451
|
+
test/resources/password_protected_sample_xlsx.xlsx:
|
|
452
|
+
comments:
|
|
453
|
+
reviewed_by: josh.pencheon
|
|
454
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
443
455
|
test/resources/sample.xml:
|
|
444
456
|
comments:
|
|
445
457
|
reviewed_by: josh.pencheon
|
|
@@ -507,11 +519,11 @@ file safety:
|
|
|
507
519
|
test/table_test.rb:
|
|
508
520
|
comments:
|
|
509
521
|
reviewed_by: josh.pencheon
|
|
510
|
-
safe_revision:
|
|
522
|
+
safe_revision: a69d4a57ddcf13cdc13c27bd2eb91a395fa7ea36
|
|
511
523
|
test/test_helper.rb:
|
|
512
524
|
comments:
|
|
513
525
|
reviewed_by: josh.pencheon
|
|
514
|
-
safe_revision:
|
|
526
|
+
safe_revision: 93ccee82fc2165d1ca2d9b03d146ae03e769ea96
|
|
515
527
|
test/universal_importer_helper_test.rb:
|
|
516
528
|
comments:
|
|
517
529
|
reviewed_by: josh.pencheon
|
data/gemfiles/Gemfile.rails50
CHANGED
data/gemfiles/Gemfile.rails51
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
+
# ooxml_decrypt is not published to rubygems.org so we need to specify where it is
|
|
4
|
+
gem 'ooxml_decrypt', git: 'https://github.com/timgentry/ooxml_decrypt'
|
|
5
|
+
|
|
3
6
|
gemspec path: '..'
|
|
4
7
|
|
|
5
8
|
# Minitest 5.10.2 doesn't work with Rails version
|
data/gemfiles/Gemfile.rails52
CHANGED
data/lib/ndr_import/file/docx.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'docx'
|
|
2
2
|
require 'ndr_support/safe_file'
|
|
3
|
+
require_relative 'office_file_helper'
|
|
3
4
|
require_relative 'registry'
|
|
4
5
|
|
|
5
6
|
module NdrImport
|
|
@@ -9,19 +10,40 @@ module NdrImport
|
|
|
9
10
|
# This class is a modern Word document file handler that returns a single table.
|
|
10
11
|
# It only works on .docx documents
|
|
11
12
|
class Docx < Base
|
|
13
|
+
include OfficeFileHelper
|
|
14
|
+
|
|
12
15
|
private
|
|
13
16
|
|
|
14
17
|
def rows(&block)
|
|
15
18
|
return enum_for(:rows) unless block
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
send(@options.key?(:file_password) ? :decrypted_path : :unencrypted_path) do |path|
|
|
21
|
+
doc = ::Docx::Document.open(path)
|
|
22
|
+
|
|
23
|
+
doc.paragraphs.each do |p|
|
|
24
|
+
yield(p.to_s)
|
|
25
|
+
end
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
yield(p.to_s)
|
|
27
|
+
doc.zip.close
|
|
21
28
|
end
|
|
22
29
|
rescue StandardError => e
|
|
23
30
|
raise("#{SafeFile.basename(@filename)} [#{e.class}: #{e.message}]")
|
|
24
31
|
end
|
|
32
|
+
|
|
33
|
+
# This method returns the path to the temporary, decrypted file
|
|
34
|
+
def decrypted_path
|
|
35
|
+
Tempfile.create(['decrypted', '.docx']) do |file|
|
|
36
|
+
file.write(decrypted_file_string(@filename, @options[:file_password]))
|
|
37
|
+
file.close
|
|
38
|
+
|
|
39
|
+
yield file.path
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# This method returns the safepath to the unencrypted docx file
|
|
44
|
+
def unencrypted_path
|
|
45
|
+
yield SafeFile.safepath_to_string(@filename)
|
|
46
|
+
end
|
|
25
47
|
end
|
|
26
48
|
|
|
27
49
|
Registry.register(Docx, 'docx')
|
|
@@ -2,6 +2,7 @@ require 'roo'
|
|
|
2
2
|
require 'roo-xls'
|
|
3
3
|
require 'ole/storage'
|
|
4
4
|
require 'ndr_support/safe_file'
|
|
5
|
+
require_relative 'office_file_helper'
|
|
5
6
|
require_relative 'registry'
|
|
6
7
|
|
|
7
8
|
module NdrImport
|
|
@@ -13,6 +14,8 @@ module NdrImport
|
|
|
13
14
|
# appropriately. These methods can be overridden or aliased as required.
|
|
14
15
|
#
|
|
15
16
|
class Excel < Base
|
|
17
|
+
include OfficeFileHelper
|
|
18
|
+
|
|
16
19
|
# Iterate through the file table by table, yielding each one in turn.
|
|
17
20
|
def tables
|
|
18
21
|
return enum_for(:tables) unless block_given?
|
|
@@ -88,7 +91,11 @@ module NdrImport
|
|
|
88
91
|
when '.xls'
|
|
89
92
|
Roo::Excel.new(SafeFile.safepath_to_string(path))
|
|
90
93
|
when '.xlsx'
|
|
91
|
-
|
|
94
|
+
if @options.key?(:file_password)
|
|
95
|
+
Roo::Excelx.new(StringIO.new(decrypted_file_string(path, @options[:file_password])))
|
|
96
|
+
else
|
|
97
|
+
Roo::Excelx.new(SafeFile.safepath_to_string(path))
|
|
98
|
+
end
|
|
92
99
|
else
|
|
93
100
|
fail "Received file path with unexpected extension #{SafeFile.extname(path)}"
|
|
94
101
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'ooxml_decrypt'
|
|
2
|
+
|
|
3
|
+
module NdrImport
|
|
4
|
+
module File
|
|
5
|
+
# This mixin provides helper methods of MS Office files
|
|
6
|
+
module OfficeFileHelper
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
# This method decrypts a (modern) password protected MS Office document
|
|
10
|
+
# returning a String of the decrypted file
|
|
11
|
+
def decrypted_file_string(path, password)
|
|
12
|
+
# Ensure password is a binary representation of a UTF-16LE string
|
|
13
|
+
# e.g. 'password' should be represented as "p\0\a\s\0[...]"
|
|
14
|
+
password = password.encode('utf-16le').bytes.pack('c*').encode('binary')
|
|
15
|
+
|
|
16
|
+
OoxmlDecrypt::EncryptedFile.decrypt(SafeFile.safepath_to_string(path), password)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/ndr_import/table.rb
CHANGED
|
@@ -10,8 +10,8 @@ module NdrImport
|
|
|
10
10
|
include NdrImport::Mapper
|
|
11
11
|
|
|
12
12
|
def self.all_valid_options
|
|
13
|
-
%w[canonical_name delimiter liberal_parsing filename_pattern tablename_pattern
|
|
14
|
-
footer_lines format klass columns xml_record_xpath row_identifier]
|
|
13
|
+
%w[canonical_name delimiter liberal_parsing filename_pattern file_password tablename_pattern
|
|
14
|
+
header_lines footer_lines format klass columns xml_record_xpath row_identifier]
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def all_valid_options
|
|
@@ -36,6 +36,7 @@ module NdrImport
|
|
|
36
36
|
options = {
|
|
37
37
|
'unzip_path' => unzip_path,
|
|
38
38
|
'col_sep' => table_mapping.try(:delimiter),
|
|
39
|
+
'file_password' => table_mapping.try(:file_password),
|
|
39
40
|
'liberal_parsing' => table_mapping.try(:liberal_parsing),
|
|
40
41
|
'xml_record_xpath' => table_mapping.try(:xml_record_xpath)
|
|
41
42
|
}
|
data/lib/ndr_import/version.rb
CHANGED
data/ndr_import.gemspec
CHANGED
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
spec.add_dependency 'docx', '~> 0.3'
|
|
31
31
|
spec.add_dependency 'msworddoc-extractor', '0.2.0'
|
|
32
32
|
spec.add_dependency 'nokogiri', '~> 1.8', '>= 1.8.5'
|
|
33
|
+
spec.add_dependency 'ooxml_decrypt'
|
|
33
34
|
spec.add_dependency 'pdf-reader', '~> 2.1'
|
|
34
35
|
spec.add_dependency 'roo-xls'
|
|
35
36
|
spec.add_dependency 'seven_zip_ruby', '~> 1.2'
|
|
@@ -37,7 +38,7 @@ Gem::Specification.new do |spec|
|
|
|
37
38
|
|
|
38
39
|
spec.required_ruby_version = '>= 2.4'
|
|
39
40
|
|
|
40
|
-
spec.add_development_dependency 'bundler'
|
|
41
|
+
spec.add_development_dependency 'bundler'
|
|
41
42
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
42
43
|
spec.add_development_dependency 'minitest'
|
|
43
44
|
spec.add_development_dependency 'mocha'
|
data/test/file/delimited_test.rb
CHANGED
|
@@ -186,7 +186,7 @@ module NdrImport
|
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
assert_match(/Invalid CSV format on row 2 of broken\.csv\./, exception.message)
|
|
189
|
-
assert_match(
|
|
189
|
+
assert_match(CORRUPTED_QUOTES_MESSAGE_PATTERN, exception.message)
|
|
190
190
|
assert_match(/in line 2/, exception.message)
|
|
191
191
|
end
|
|
192
192
|
|
|
@@ -208,7 +208,7 @@ module NdrImport
|
|
|
208
208
|
assert rows_yielded.empty?, 'no rows should have been yielded'
|
|
209
209
|
|
|
210
210
|
assert_match(/Invalid CSV format on row 2 of broken\.csv\./, exception.message)
|
|
211
|
-
assert_match(
|
|
211
|
+
assert_match(CORRUPTED_QUOTES_MESSAGE_PATTERN, exception.message)
|
|
212
212
|
assert_match(/in line 2/, exception.message)
|
|
213
213
|
end
|
|
214
214
|
|
data/test/file/docx_test.rb
CHANGED
|
@@ -23,6 +23,20 @@ module NdrImport
|
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
test 'should read password protected word file' do
|
|
27
|
+
file_path = @permanent_test_files.join('password_protected_hello_world.docx')
|
|
28
|
+
handler = NdrImport::File::Docx.new(file_path, nil, file_password: 'salad')
|
|
29
|
+
handler.tables.each do |tablename, sheet|
|
|
30
|
+
assert_nil tablename
|
|
31
|
+
assert_instance_of Enumerator, sheet
|
|
32
|
+
assert_equal [
|
|
33
|
+
'Hello world, this is a modern word document',
|
|
34
|
+
'With more than one line of text',
|
|
35
|
+
'Three in fact'
|
|
36
|
+
], sheet.to_a
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
26
40
|
test 'should raise exception on invalid word file' do
|
|
27
41
|
assert_raises RuntimeError do
|
|
28
42
|
file_path = @permanent_test_files.join('not_a_word_file.docx')
|
data/test/file/excel_test.rb
CHANGED
|
@@ -70,6 +70,16 @@ module NdrImport
|
|
|
70
70
|
SafeFile.delete @permanent_test_files.join('xlsx_file_xls_extension_amend.xlsx')
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
+
test 'should read password protected xlsx file' do
|
|
74
|
+
file_path = @permanent_test_files.join('password_protected_sample_xlsx.xlsx')
|
|
75
|
+
handler = NdrImport::File::Excel.new(file_path, nil, file_password: 'carrot')
|
|
76
|
+
handler.tables.each do |tablename, sheet|
|
|
77
|
+
assert_equal 'Sheet1', tablename
|
|
78
|
+
assert_instance_of Enumerator, sheet
|
|
79
|
+
assert_equal %w(1A 1B), sheet.first
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
73
83
|
test 'read_excel_file helper should handle exceptions' do
|
|
74
84
|
# txt file
|
|
75
85
|
assert_raises RuntimeError do
|
|
@@ -60,7 +60,7 @@ class DelimitedTest < ActiveSupport::TestCase
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
assert_match(/Invalid CSV format on row 2 of broken\.csv\./, exception.message)
|
|
63
|
-
assert_match(
|
|
63
|
+
assert_match(CORRUPTED_QUOTES_MESSAGE_PATTERN, exception.message)
|
|
64
64
|
assert_match(/in line 2/, exception.message)
|
|
65
65
|
end
|
|
66
66
|
|
|
@@ -88,7 +88,7 @@ class DelimitedTest < ActiveSupport::TestCase
|
|
|
88
88
|
assert rows_yielded.empty?, 'no rows should have been yielded'
|
|
89
89
|
|
|
90
90
|
assert_match(/Invalid CSV format on row 2 of broken\.csv\./, exception.message)
|
|
91
|
-
assert_match(
|
|
91
|
+
assert_match(CORRUPTED_QUOTES_MESSAGE_PATTERN, exception.message)
|
|
92
92
|
assert_match(/in line 2/, exception.message)
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -49,7 +49,8 @@ STR
|
|
|
49
49
|
def test_all_valid_options
|
|
50
50
|
valid_options = %w[
|
|
51
51
|
canonical_name capture_end_line capture_start_line columns end_in_a_record end_line_pattern
|
|
52
|
-
filename_pattern format klass remove_lines row_identifier start_in_a_record
|
|
52
|
+
filename_pattern file_password format klass remove_lines row_identifier start_in_a_record
|
|
53
|
+
start_line_pattern
|
|
53
54
|
]
|
|
54
55
|
assert_equal valid_options.sort,
|
|
55
56
|
NdrImport::NonTabular::Table.all_valid_options.sort
|
|
Binary file
|
|
Binary file
|
data/test/table_test.rb
CHANGED
|
@@ -19,14 +19,15 @@ class TableTest < ActiveSupport::TestCase
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def test_initialize
|
|
22
|
-
table = NdrImport::Table.new(:
|
|
23
|
-
:
|
|
24
|
-
:
|
|
22
|
+
table = NdrImport::Table.new(header_lines: 2, file_password: 'leek', footer_lines: 1,
|
|
23
|
+
format: 'pipe', klass: 'SomeTestKlass',
|
|
24
|
+
columns: [{ 'column' => 'one' }, { 'column' => 'two' }])
|
|
25
25
|
assert_instance_of NdrImport::Table, table
|
|
26
26
|
assert_equal 2, table.header_lines
|
|
27
27
|
assert_equal 1, table.footer_lines
|
|
28
28
|
assert_equal 'pipe', table.format
|
|
29
29
|
assert_equal 'SomeTestKlass', table.klass
|
|
30
|
+
assert_equal 'leek', table.file_password
|
|
30
31
|
assert_equal [{ 'column' => 'one' }, { 'column' => 'two' }], table.columns
|
|
31
32
|
end
|
|
32
33
|
|
data/test/test_helper.rb
CHANGED
|
@@ -25,4 +25,11 @@ NdrImport::StandardMappings.mappings = YAML.load_file(
|
|
|
25
25
|
File.expand_path(File.dirname(__FILE__) + '/resources/standard_mappings.yml')
|
|
26
26
|
)
|
|
27
27
|
|
|
28
|
+
# Different Rubies report this differently:
|
|
29
|
+
CORRUPTED_QUOTES_MESSAGE_PATTERN = /(
|
|
30
|
+
Missing\sor\sstray\squote|
|
|
31
|
+
col_sep_split|
|
|
32
|
+
value\safter\squoted\sfield\sisn't\sallowed
|
|
33
|
+
)/x
|
|
34
|
+
|
|
28
35
|
require 'mocha/minitest'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ndr_import
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 8.
|
|
4
|
+
version: 8.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- NCRS Development Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-05-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activemodel
|
|
@@ -140,6 +140,20 @@ dependencies:
|
|
|
140
140
|
- - ">="
|
|
141
141
|
- !ruby/object:Gem::Version
|
|
142
142
|
version: 1.8.5
|
|
143
|
+
- !ruby/object:Gem::Dependency
|
|
144
|
+
name: ooxml_decrypt
|
|
145
|
+
requirement: !ruby/object:Gem::Requirement
|
|
146
|
+
requirements:
|
|
147
|
+
- - ">="
|
|
148
|
+
- !ruby/object:Gem::Version
|
|
149
|
+
version: '0'
|
|
150
|
+
type: :runtime
|
|
151
|
+
prerelease: false
|
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
153
|
+
requirements:
|
|
154
|
+
- - ">="
|
|
155
|
+
- !ruby/object:Gem::Version
|
|
156
|
+
version: '0'
|
|
143
157
|
- !ruby/object:Gem::Dependency
|
|
144
158
|
name: pdf-reader
|
|
145
159
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -200,16 +214,16 @@ dependencies:
|
|
|
200
214
|
name: bundler
|
|
201
215
|
requirement: !ruby/object:Gem::Requirement
|
|
202
216
|
requirements:
|
|
203
|
-
- - "
|
|
217
|
+
- - ">="
|
|
204
218
|
- !ruby/object:Gem::Version
|
|
205
|
-
version: '
|
|
219
|
+
version: '0'
|
|
206
220
|
type: :development
|
|
207
221
|
prerelease: false
|
|
208
222
|
version_requirements: !ruby/object:Gem::Requirement
|
|
209
223
|
requirements:
|
|
210
|
-
- - "
|
|
224
|
+
- - ">="
|
|
211
225
|
- !ruby/object:Gem::Version
|
|
212
|
-
version: '
|
|
226
|
+
version: '0'
|
|
213
227
|
- !ruby/object:Gem::Dependency
|
|
214
228
|
name: rake
|
|
215
229
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -371,6 +385,7 @@ files:
|
|
|
371
385
|
- lib/ndr_import/file/delimited.rb
|
|
372
386
|
- lib/ndr_import/file/docx.rb
|
|
373
387
|
- lib/ndr_import/file/excel.rb
|
|
388
|
+
- lib/ndr_import/file/office_file_helper.rb
|
|
374
389
|
- lib/ndr_import/file/pdf.rb
|
|
375
390
|
- lib/ndr_import/file/registry.rb
|
|
376
391
|
- lib/ndr_import/file/seven_zip.rb
|
|
@@ -458,6 +473,8 @@ files:
|
|
|
458
473
|
- test/resources/not_a_word_file.doc
|
|
459
474
|
- test/resources/not_a_word_file.docx
|
|
460
475
|
- test/resources/not_sign_delimited.txt
|
|
476
|
+
- test/resources/password_protected_hello_world.docx
|
|
477
|
+
- test/resources/password_protected_sample_xlsx.xlsx
|
|
461
478
|
- test/resources/sample.xml
|
|
462
479
|
- test/resources/sample_xls.xls
|
|
463
480
|
- test/resources/sample_xlsx.xlsx
|
|
@@ -497,7 +514,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
497
514
|
- !ruby/object:Gem::Version
|
|
498
515
|
version: '0'
|
|
499
516
|
requirements: []
|
|
500
|
-
rubygems_version: 3.0.
|
|
517
|
+
rubygems_version: 3.0.3
|
|
501
518
|
signing_key:
|
|
502
519
|
specification_version: 4
|
|
503
520
|
summary: NDR Import
|
|
@@ -557,6 +574,8 @@ test_files:
|
|
|
557
574
|
- test/resources/not_a_word_file.doc
|
|
558
575
|
- test/resources/not_a_word_file.docx
|
|
559
576
|
- test/resources/not_sign_delimited.txt
|
|
577
|
+
- test/resources/password_protected_hello_world.docx
|
|
578
|
+
- test/resources/password_protected_sample_xlsx.xlsx
|
|
560
579
|
- test/resources/sample.xml
|
|
561
580
|
- test/resources/sample_xls.xls
|
|
562
581
|
- test/resources/sample_xlsx.xlsx
|