ngzip 1.1.0 → 1.2.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
  SHA256:
3
- metadata.gz: 84899280f348b240160b5c6984b7a4130a7a48f71b9c7d903051f99a36326f09
4
- data.tar.gz: 1b1b057b9da9d80900035e732ed586b13c9e5a25659b4b9ac226862f7d6782b4
3
+ metadata.gz: 456fae1b62d713966116eba3fc4a54ed579722faee0eb6c70f10559ed9777417
4
+ data.tar.gz: 77b9dc4077689d672b732025c41e913e6b6326c4659a7eeaa36c190a6d7d2089
5
5
  SHA512:
6
- metadata.gz: 6f5b599664e6b4f49de86596596ae5bdae4f9ab8601c260e58e075c6376d6a37c5aa25a441baa971cf590a1b11d218e675369e67140ca9076df197fc2c62aeaa
7
- data.tar.gz: 815fb0735456a2020781276b456c47e8e76d567e2ef8b35bcd65856e38913c55e00c717cb1a0ced8da4f8e39d1d9febf9deec9645dcb9d2bf4de2790520ddee1
6
+ metadata.gz: '09275f7ae55b7c94af391eb829f6810016093a57ae550cad93f82f9f5e7c2ca99eea7e9781bc9f895ca97a22ffa39e845fac6449b196768bd502b3f36a88069b'
7
+ data.tar.gz: 6f0fcb9a9daf07ac7de34d468591bdb1920644eb8c2691b4b63a100ce59f0cf5005c7569f51d99bd47d9d6f0c256f2326e27a40d944e63b36e95cdb24ef8a2db
@@ -0,0 +1,16 @@
1
+ env:
2
+ RUBY_VERSION: 2.6.6
3
+ name: Rspec tests
4
+ on: [push,pull_request]
5
+ jobs:
6
+ rspec-tests:
7
+ name: RSpec
8
+ runs-on: ubuntu-18.04
9
+ steps:
10
+ - uses: actions/checkout@v1
11
+ - uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: ${{ env.RUBY_VERSION }}
14
+ bundler-cache: true
15
+ - name: Run tests
16
+ run: bundler exec rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 1.2.0 (2021-07-08)
2
+
3
+ * Fixed an issue with brackets in file names (thanks to @mecampbellsoup)
4
+ * Code cleanup
5
+ * Fixed dependencies
6
+ * Activated github CI actions
7
+
8
+ ### 1.1.0 (2020-11-25)
9
+
10
+ * Exclude file name from detect common prefix (thanks to @mecampbellsoup)
11
+ * Code cleanup
12
+
1
13
  ### 1.0.7 (2017-10-20)
2
14
 
3
15
  * Fixed an issue with '?' encoding
data/README.md CHANGED
@@ -68,5 +68,6 @@ fetch the actual file data and would support any location type (even proxied).
68
68
 
69
69
  Copyright (c) 2013, ncode gmbh. All Rights Reserved.
70
70
  Copyright (c) 2017, CargoServer AG. All Rights Reserved.
71
+ Copyright (c) 2021, Swiss Cyber Gate AG. All Rights Reserved.
71
72
 
72
73
  This project is licenced under the [MIT License](LICENSE.txt).
data/lib/ngzip/builder.rb CHANGED
@@ -3,6 +3,9 @@
3
3
  require 'zlib'
4
4
  require 'uri'
5
5
  require 'erb'
6
+ require 'refinements'
7
+
8
+ using Refinements
6
9
 
7
10
  module Ngzip
8
11
  # The manifest builder based on the file list
@@ -81,7 +84,8 @@ module Ngzip
81
84
  Array(files).map do |e|
82
85
  if File.directory?(e)
83
86
  # `expand_path` removes any trailing slash from the path string
84
- sanitized_path = File.expand_path(e)
87
+ # `String#escape_glob` handles bracket literals otherwise interpreted as glob control characters
88
+ sanitized_path = File.expand_path(e.escape_glob)
85
89
  Dir.glob("#{sanitized_path}/**/*").reject { |f| File.directory?(f) }
86
90
  else
87
91
  e
data/lib/ngzip/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ngzip
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -0,0 +1,9 @@
1
+ module Refinements
2
+ refine String do
3
+ # Ref: https://stackoverflow.com/questions/14127343/why-dir-glob-in-ruby-doesnt-see-files-in-folders-named-with-square-brackets
4
+ # Ref: https://bugs.ruby-lang.org/issues/8258
5
+ def escape_glob
6
+ self.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\" + x }
7
+ end
8
+ end
9
+ end
data/ngzip.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'english'
5
+ require 'English'
6
6
  require 'ngzip/version'
7
7
 
8
8
  Gem::Specification.new do |spec|
@@ -20,8 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
22
  spec.require_paths = ['lib']
23
+ spec.required_ruby_version = '>= 2.3'
23
24
 
24
- spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'bundler', '>= 2.2.10'
25
26
  spec.add_development_dependency 'rake'
26
27
  spec.add_development_dependency 'rubocop'
27
28
  end
@@ -0,0 +1,3 @@
1
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
2
+
3
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -16,16 +16,17 @@ describe Ngzip::Builder do
16
16
  end
17
17
 
18
18
  let(:builder) { Ngzip::Builder.new }
19
+ let(:sit) { File.expand_path('../../data/sit.txt', __dir__) }
19
20
  let(:lorem) { File.expand_path('../../data/a/lorem.txt', __dir__) }
20
21
  let(:ipsum) { File.expand_path('../../data/a/ipsum.txt', __dir__) }
21
- let(:without_dot) { File.expand_path('../../data/a/filename-without-a-dot', __dir__) }
22
22
  let(:my_file) { File.expand_path('../../data/a/d/my_file.txt', __dir__) }
23
+ let(:without_dot) { File.expand_path('../../data/a/filename-without-a-dot', __dir__) }
23
24
  let(:whitespaced) { File.expand_path('../../data/a/A filename with whitespace.txt', __dir__) }
24
- let(:plused) { File.expand_path('../../data/c/A filename with space and + in it.txt', __dir__) }
25
- let(:cargo) { File.expand_path('../../data/b/Cargo.png', __dir__) }
26
- let(:sit) { File.expand_path('../../data/sit.txt', __dir__) }
27
25
  let(:a) { File.expand_path('../../data/a', __dir__) }
26
+ let(:cargo) { File.expand_path('../../data/b/Cargo.png', __dir__) }
27
+ let(:plused) { File.expand_path('../../data/c/A filename with space and + in it.txt', __dir__) }
28
28
  let(:questions) { File.expand_path('../../data/c/questions?', __dir__) }
29
+ let(:brackets) { File.expand_path('../../data/c/[brackets]', __dir__) }
29
30
 
30
31
  it 'must be defined' do
31
32
  expect(Ngzip::Builder).wont_be_nil
@@ -67,24 +68,26 @@ describe Ngzip::Builder do
67
68
  end
68
69
 
69
70
  it 'must return a correct list for all files in a directory' do
70
- expected = StringIO.new
71
- expected << "8f92322f 446 #{encode_file_path(whitespaced)} A filename with whitespace.txt"
72
- expected << "\n8f92322f 446 #{encode_file_path(without_dot)} filename-without-a-dot"
73
- expected << "\n8f92322f 446 #{encode_file_path(ipsum)} ipsum.txt"
74
- expected << "\n8f92322f 446 #{encode_file_path(lorem)} lorem.txt"
75
- expected << "\n8f92322f 446 #{encode_file_path(my_file)} d/my_file.txt"
76
- expect(builder.build(a, options)).must_equal expected.string
71
+ expected = <<~MANIFEST.chomp
72
+ 8f92322f 446 #{encode_file_path(whitespaced)} A filename with whitespace.txt
73
+ 8f92322f 446 #{encode_file_path(without_dot)} filename-without-a-dot
74
+ 8f92322f 446 #{encode_file_path(ipsum)} ipsum.txt
75
+ 8f92322f 446 #{encode_file_path(lorem)} lorem.txt
76
+ 8f92322f 446 #{encode_file_path(my_file)} d/my_file.txt
77
+ MANIFEST
78
+ expect(builder.build(a, options).lines.sort.map(&:chomp)).must_equal expected.lines.sort.map(&:chomp)
77
79
  end
78
80
 
79
81
  it 'must allow to mix files and directories' do
80
- expected = StringIO.new
81
- expected << "8f92322f 446 #{encode_file_path(whitespaced)} a/A filename with whitespace.txt"
82
- expected << "\n8f92322f 446 #{encode_file_path(without_dot)} a/filename-without-a-dot"
83
- expected << "\n8f92322f 446 #{encode_file_path(ipsum)} a/ipsum.txt"
84
- expected << "\n8f92322f 446 #{encode_file_path(lorem)} a/lorem.txt"
85
- expected << "\n8f92322f 446 #{encode_file_path(my_file)} a/d/my_file.txt"
86
- expected << "\nf7c0867d 1342 #{encode_file_path(sit)} sit.txt"
87
- expect(builder.build([a, sit], options)).must_equal expected.string
82
+ expected = <<~MANIFEST.chomp
83
+ 8f92322f 446 #{encode_file_path(whitespaced)} a/A filename with whitespace.txt
84
+ 8f92322f 446 #{encode_file_path(without_dot)} a/filename-without-a-dot
85
+ 8f92322f 446 #{encode_file_path(ipsum)} a/ipsum.txt
86
+ 8f92322f 446 #{encode_file_path(lorem)} a/lorem.txt
87
+ 8f92322f 446 #{encode_file_path(my_file)} a/d/my_file.txt
88
+ f7c0867d 1342 #{encode_file_path(sit)} sit.txt
89
+ MANIFEST
90
+ expect(builder.build([a, sit], options).lines.sort.map(&:chomp)).must_equal expected.lines.sort.map(&:chomp)
88
91
  end
89
92
 
90
93
  it 'must preserve directory names' do
@@ -109,6 +112,17 @@ describe Ngzip::Builder do
109
112
  end
110
113
 
111
114
  describe 'when building the manifest from a directory path parameter' do
115
+ describe 'the path includes brackets' do
116
+ it 'handles special characters in file names' do
117
+ result = builder.build(brackets)
118
+ encoded_host_path = ERB::Util.url_encode(File.join(File.expand_path('../data', File.dirname(__dir__)), '/'))
119
+ manifest = <<~MANIFEST.chomp
120
+ dee5e05b 894 #{encoded_host_path}c%2F%5Bbrackets%5D%2F%28parenthesis%29.txt (parenthesis).txt
121
+ MANIFEST
122
+ expect(result).must_equal manifest
123
+ end
124
+ end
125
+
112
126
  it 'removes trailing slash from builder file path' do
113
127
  dir_path = File.join(File.dirname(lorem), '/')
114
128
  result = builder.build(dir_path)
@@ -120,7 +134,7 @@ describe Ngzip::Builder do
120
134
  8f92322f 446 #{encoded_host_path}a%2Florem.txt lorem.txt
121
135
  8f92322f 446 #{encoded_host_path}a%2Fd%2Fmy_file.txt d/my_file.txt
122
136
  MANIFEST
123
- expect(result).must_equal manifest
137
+ expect(result.lines.sort.map(&:chomp)).must_equal manifest.lines.sort.map(&:chomp)
124
138
  end
125
139
  end
126
140
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ngzip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dup2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: 2.2.10
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: 2.2.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -61,6 +61,7 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
+ - ".github/workflows/rspec.yaml"
64
65
  - ".gitignore"
65
66
  - CHANGELOG.md
66
67
  - Gemfile
@@ -70,6 +71,7 @@ files:
70
71
  - lib/ngzip.rb
71
72
  - lib/ngzip/builder.rb
72
73
  - lib/ngzip/version.rb
74
+ - lib/refinements.rb
73
75
  - ngzip.gemspec
74
76
  - test/data/a/A filename with whitespace.txt
75
77
  - test/data/a/d/my_file.txt
@@ -79,6 +81,7 @@ files:
79
81
  - test/data/b/Cargo.png
80
82
  - test/data/b/dolor.txt
81
83
  - test/data/c/A filename with space and + in it.txt
84
+ - test/data/c/[brackets]/(parenthesis).txt
82
85
  - test/data/c/questions?/test.txt
83
86
  - test/data/sit.txt
84
87
  - test/lib/ngzip/builder_test.rb
@@ -96,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
99
  requirements:
97
100
  - - ">="
98
101
  - !ruby/object:Gem::Version
99
- version: '0'
102
+ version: '2.3'
100
103
  required_rubygems_version: !ruby/object:Gem::Requirement
101
104
  requirements:
102
105
  - - ">="
@@ -116,6 +119,7 @@ test_files:
116
119
  - test/data/b/Cargo.png
117
120
  - test/data/b/dolor.txt
118
121
  - test/data/c/A filename with space and + in it.txt
122
+ - test/data/c/[brackets]/(parenthesis).txt
119
123
  - test/data/c/questions?/test.txt
120
124
  - test/data/sit.txt
121
125
  - test/lib/ngzip/builder_test.rb