files.com 1.1.781 → 1.1.782

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffd672a0d5481d8fa675628cf4b80f3c0859da27de244e1cf8749ddfa066984c
4
- data.tar.gz: cdc1c6102a5beb1917888f7fd1885f2d67b9832b0f50003237b9860638fd367d
3
+ metadata.gz: ddcd318206fe185a4e00ccbfb7d6d2d4655a1f7810800a341bbfbe5132d17a17
4
+ data.tar.gz: 65523517081a2759ad980a8cf43198e49bbb684609ba5d4512adda9ead3cf78b
5
5
  SHA512:
6
- metadata.gz: a812771f0ed9ff2822e31c65636de9dd02440aae18a25e1656ea0cede8d041d47d9324be207572db8d2473b4a3ac19ac85859f52d2aa2572decafea24dc2ba0a
7
- data.tar.gz: a98a193201652c9a732ad86931528eca0410b1f5a4d32400ec12b751c5acea784cc8ea0e4b6e7811e6bd087056c04df530fc2847de78cb88bd99082d9b6a81e5
6
+ metadata.gz: 84dabf3483704390c691c4e2cb5b0ba75d7c12ef96e0a0559512cb7ebc674d8cf43813a720df47b7e8b4a3b9518ed0d3bace0f3ffc23fa95acf8e8f5dbcd2617
7
+ data.tar.gz: 2873fd9698c3b0395217b4463d5613d39b6c42f7c70e0b0cbf29dec4d337095906494feadd85c04ec2a0735f381d248b0ff56a2ce57f6efac30acba0f35e3d1f
data/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.781
1
+ 1.1.782
@@ -5,6 +5,13 @@ module Files
5
5
  attr_reader :options, :attributes
6
6
  attr_reader :mode
7
7
 
8
+ WINDOWS_DEVICE_NAMES = [
9
+ "CON", "PRN", "AUX", "NUL", "CONIN$", "CONOUT$",
10
+ "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM\u00b9", "COM\u00b2", "COM\u00b3",
11
+ "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "LPT\u00b9", "LPT\u00b2", "LPT\u00b3"
12
+ ].freeze
13
+ private_constant :WINDOWS_DEVICE_NAMES
14
+
8
15
  def self.binread(name, *args)
9
16
  new(name).read(*args)
10
17
  end
@@ -41,12 +48,24 @@ module Files
41
48
  private_class_method def self.default_local_path(path)
42
49
  name = PathUtil.normalize(path).split("/").last.to_s
43
50
  # On Windows a colon makes the name a drive-relative path or an NTFS
44
- # stream, which can write outside the working directory or onto another file.
45
- raise InvalidParameterError.new("Bad parameter: local_path is required because #{name.inspect} is not a valid local file name") if Gem.win_platform? && name.include?(":")
51
+ # stream, which can write outside the working directory or onto another
52
+ # file, and a device name such as NUL writes to the device instead of a file.
53
+ raise InvalidParameterError.new("Bad parameter: local_path is required because #{name.inspect} is not a valid local file name") if Gem.win_platform? && (name.include?(":") || windows_device_name?(name))
46
54
 
47
55
  name
48
56
  end
49
57
 
58
+ # A bare device name is always a device. Anything after it, such as the
59
+ # extension in NUL.txt, makes it a device on some Windows versions and a
60
+ # file on others, so Windows decides those names: it resolves a device to
61
+ # a //./ path.
62
+ private_class_method def self.windows_device_name?(name)
63
+ base = name.split(".", 2).first.to_s.sub(/ +\z/, "")
64
+ return false unless WINDOWS_DEVICE_NAMES.include?(base.upcase)
65
+
66
+ base == name || ::File.absolute_path(name).start_with?("//./")
67
+ end
68
+
50
69
  private_class_method def self.underscore_destination_path(root, id, relative_path = nil)
51
70
  PathUtil.normalize("_", root, id.to_s, relative_path)
52
71
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Files
4
- VERSION = "1.1.781"
4
+ VERSION = "1.1.782"
5
5
  end
@@ -11,10 +11,10 @@ RSpec.describe Files::File do
11
11
  described_class.download_file("folder/report:2026.txt")
12
12
  end
13
13
 
14
- it "refuses a drive or stream name on Windows" do
14
+ it "refuses a drive, stream, or device name on Windows" do
15
15
  allow(Gem).to receive(:win_platform?).and_return(true)
16
16
 
17
- [ "folder/C:victim.txt", "C:victim.txt", "folder/victim.txt::$DATA" ].each do |remote_path|
17
+ [ "folder/C:victim.txt", "C:victim.txt", "folder/victim.txt::$DATA", "folder/NUL", "folder/con", "COM1", "folder/CONIN$" ].each do |remote_path|
18
18
  expect { described_class.download_file(remote_path) }.to raise_error(Files::InvalidParameterError)
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: files.com
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.781
4
+ version: 1.1.782
5
5
  platform: ruby
6
6
  authors:
7
7
  - files.com