file-uri 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/file-uri/win.rb +72 -0
- data/test/test-win-file-uri.rb +19 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3525f546d39d44784846b1f02a372cf6bb78b555
|
4
|
+
data.tar.gz: e23b88aa0f6bfa10d88c9fc29c15466c1c37ec48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ae089e1b4a47e938587b75300a43a334fb9df07c1b292373960ad4928d3990106229fe27daba337de6a3787c4500e7d9c3d21ef6dad9989e9aa4def13ada888
|
7
|
+
data.tar.gz: b66d19dfa6aa6025d46990af64fa1f178151d1ea4942648f41e190b7188b387fa0bf6f54936e60bd2039bd15e1286e898df1c176d8deda4909e744ac8ca09b80
|
data/lib/file-uri/win.rb
CHANGED
@@ -46,6 +46,78 @@ module URI
|
|
46
46
|
super(scheme, userinfo, host, port, registry, path, opaque, query, fragment, parser, arg_check)
|
47
47
|
end
|
48
48
|
|
49
|
+
#
|
50
|
+
# == Args
|
51
|
+
#
|
52
|
+
# +oth+::
|
53
|
+
# URI or String
|
54
|
+
#
|
55
|
+
# == Description
|
56
|
+
#
|
57
|
+
# Merges two URI's.
|
58
|
+
#
|
59
|
+
# == Usage
|
60
|
+
#
|
61
|
+
# require 'uri'
|
62
|
+
#
|
63
|
+
# uri = URI.parse("http://my.example.com")
|
64
|
+
# p uri.merge("/main.rbx?page=1")
|
65
|
+
# # => #<URI::HTTP:0x2021f3b0 URL:http://my.example.com/main.rbx?page=1>
|
66
|
+
#
|
67
|
+
def merge(oth)
|
68
|
+
rel = parser.send(:convert_to_uri, oth)
|
69
|
+
|
70
|
+
if rel.absolute?
|
71
|
+
#raise BadURIError, "both URI are absolute" if absolute?
|
72
|
+
# hmm... should return oth for usability?
|
73
|
+
return rel
|
74
|
+
end
|
75
|
+
|
76
|
+
unless self.absolute?
|
77
|
+
raise BadURIError, "both URI are relative"
|
78
|
+
end
|
79
|
+
|
80
|
+
base = self.dup
|
81
|
+
|
82
|
+
authority = rel.userinfo || rel.host || rel.port
|
83
|
+
|
84
|
+
# RFC2396, Section 5.2, 2)
|
85
|
+
if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
|
86
|
+
base.fragment=(rel.fragment) if rel.fragment
|
87
|
+
return base
|
88
|
+
end
|
89
|
+
|
90
|
+
base.query = nil
|
91
|
+
base.fragment=(nil)
|
92
|
+
|
93
|
+
# RFC2396, Section 5.2, 4)
|
94
|
+
if !authority
|
95
|
+
# Difference from URI::Generic -- handle drive letter
|
96
|
+
base_path = base.path
|
97
|
+
rel_path = rel.path
|
98
|
+
if base_path && rel_path
|
99
|
+
if rel_path =~ %r[\A(\.\.(?=/|\z)|/(?![A-Z]:(/|\z)))]i && base_path.sub!(%r[\A/?[A-Z]:(?=/|\z)]i, '')
|
100
|
+
base.set_path($~[0] + merge_path(base_path, rel_path))
|
101
|
+
else
|
102
|
+
base.set_path(merge_path(base_path, rel_path))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
else
|
106
|
+
# RFC2396, Section 5.2, 4)
|
107
|
+
base.set_path(rel.path) if rel.path
|
108
|
+
end
|
109
|
+
|
110
|
+
# RFC2396, Section 5.2, 7)
|
111
|
+
base.set_userinfo(rel.userinfo) if rel.userinfo
|
112
|
+
base.set_host(rel.host) if rel.host
|
113
|
+
base.set_port(rel.port) if rel.port
|
114
|
+
base.query = rel.query if rel.query
|
115
|
+
base.fragment=(rel.fragment) if rel.fragment
|
116
|
+
|
117
|
+
return base
|
118
|
+
end # merge
|
119
|
+
alias + merge
|
120
|
+
|
49
121
|
##
|
50
122
|
# localhost:
|
51
123
|
#
|
data/test/test-win-file-uri.rb
CHANGED
@@ -111,4 +111,23 @@ class Test_win_file_uri < Test::Unit::TestCase
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
+
def test_relative_resolution
|
115
|
+
[
|
116
|
+
# relative references beginning with dots
|
117
|
+
['file:/c:/z/y/x', './a', '/c:/z/y/a'], # \
|
118
|
+
['file:/c:/z/y/x', '../a', '/c:/z/a'], # ) normal relative resolution
|
119
|
+
['file:/c:/z/y/x', '../../a', '/c:/a'], # /
|
120
|
+
['file:/c:/z/y/x', '../../../a', '/c:/a'], # \_ don't overwrite drive letter
|
121
|
+
['file:/c:/z/y/x', '../../../../a', '/c:/a'], # /
|
122
|
+
# ... beginning with a slash
|
123
|
+
['file:/c:/z/y/x', '/a', '/c:/a'], # relative to drive letter
|
124
|
+
['file:/c:/z/y/x', '/d:/a', '/d:/a'], # whole absolute path
|
125
|
+
['file:/c:/z/y/x', '/../a', '/c:/a'], # weird (but legal) reference
|
126
|
+
].each do |base, rel, merged_path|
|
127
|
+
b = URI.parse(base)
|
128
|
+
m = b + rel
|
129
|
+
assert_equal( merged_path, m.path, "#{base.inspect} + #{rel.inspect}")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
114
133
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file-uri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
== file-uri – the "file" URI Scheme
|
@@ -50,7 +50,7 @@ rubyforge_project:
|
|
50
50
|
rubygems_version: 2.6.7
|
51
51
|
signing_key:
|
52
52
|
specification_version: 4
|
53
|
-
summary:
|
53
|
+
summary: file-uri – the "file" URI Scheme
|
54
54
|
test_files:
|
55
55
|
- test/test-win-file-uri.rb
|
56
56
|
- test/test-file-uri.rb
|