file-uri 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6a645851a1f2159e72eafaefd02f0d740bead9e
4
- data.tar.gz: 0aa68c3ae8150ac81653498069c7fab57693db65
3
+ metadata.gz: 3525f546d39d44784846b1f02a372cf6bb78b555
4
+ data.tar.gz: e23b88aa0f6bfa10d88c9fc29c15466c1c37ec48
5
5
  SHA512:
6
- metadata.gz: bb872d4478f27ec8c8a63e36499db67742c271e1431a34c1770bf86b96bf7a0492727a5d1ecafb656452ffaa1f1b82f50f0e2dbae1700e15b5c5bf1b2f409b54
7
- data.tar.gz: 71ec8ecde2ea8631276db2475f3b9b3de89cec206e4c41999348c6ceb3153de322e12bcfa1a56a596547460f7e7375752a68da5c5fcb49d43486b4d244c0e547
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
  #
@@ -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.1
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-06 00:00:00.000000000 Z
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: 'file-uri : the "file" URI Scheme'
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