uri-whatwg_parser 0.1.6 → 0.1.7

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: 712c7079461310fdab82e79bea4491ce91a4a8b26827a338334a0e161520a8c0
4
- data.tar.gz: 85871841fdee54a61c942134398bfb85e2e89f798144921464058e4edd2ea8fb
3
+ metadata.gz: ff938b4f5dd4b3fa34e438b6b4eed8498b93da3c0b2efad53ab17259376dc745
4
+ data.tar.gz: 50574a50b4bc9003d95cad80b41ba433849296bc20fe1ef7f512032e66bc2a2b
5
5
  SHA512:
6
- metadata.gz: 42b046952ea2817c3db80edcc69bafbf86822c9b88f23837b4decb9d9693b0044f68b9a74c920707e16ee28121f2c03d6992df300227b32cf62a3995e7af7ee5
7
- data.tar.gz: aa9c3d27934eec97f11f579cc2b194b5b88f0d69da5c224cb4ebf6fd13878c8a493a7e3391f7f985674e602629da303364aa49c7ed9b88f0b101b66c304db6d2
6
+ metadata.gz: da00460b289f008965b15bb943a1d1fd21339ce2224fbb2a9b64997d044a38962982d9f90dbda0886888be35b7eea363476fd3da5a532b6d88453c2cdd07923b
7
+ data.tar.gz: fb82af80a91e4e5c96caf0d478e3dd2f7f89181f4ad634c0e65fb9e589de2fdeb04fc12cc97c3a1aa2ed98ed0423670d7de05025f7c5c9dda20e5f466469e9e9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.7
2
+
3
+ * Allow to call `URI.split` multiple times
4
+ * Fix parsing a username without a password
5
+ * Support `#merge` method
6
+
1
7
  ## 0.1.6
2
8
 
3
9
  * Fix `opaque` part parsing
@@ -0,0 +1,14 @@
1
+ require "uri/generic"
2
+
3
+ module URI
4
+ class WhatwgParser
5
+ module Generic
6
+ def merge(oth)
7
+ URI::DEFAULT_PARSER.join(self.to_s, oth.to_s)
8
+ end
9
+ alias + merge
10
+ end
11
+ end
12
+ end
13
+
14
+ URI::Generic.prepend(URI::WhatwgParser::Generic)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module URI
4
4
  class WhatwgParser
5
- VERSION = "0.1.6"
5
+ VERSION = "0.1.7"
6
6
  end
7
7
  end
@@ -5,6 +5,7 @@ require_relative "whatwg_parser/error"
5
5
  require_relative "whatwg_parser/version"
6
6
  require_relative "whatwg_parser/parser_helper"
7
7
  require_relative "whatwg_parser/host_parser"
8
+ require_relative "whatwg_parser/generic"
8
9
 
9
10
  module URI
10
11
  class WhatwgParser
@@ -35,11 +36,11 @@ module URI
35
36
  end
36
37
 
37
38
  def parse(uri, base = nil, encoding = Encoding::UTF_8) # :nodoc:
38
- reset
39
39
  URI.for(*self.split(uri, base, encoding))
40
40
  end
41
41
 
42
42
  def split(uri, base = nil, encoding = Encoding::UTF_8) # :nodoc:
43
+ reset
43
44
  @base = nil
44
45
  if base != nil
45
46
  ary = split(base, nil, encoding)
@@ -66,7 +67,7 @@ module URI
66
67
  @pos += 1
67
68
  end
68
69
 
69
- @parse_result[:userinfo] = "#{@username}:#{@password}" if !@username.nil? || !@password.nil?
70
+ @parse_result[:userinfo] = [@username, @password].compact.reject(&:empty?).join(":")
70
71
  @parse_result[:path] = "/#{@paths.join("/")}" if @paths && !@paths.empty?
71
72
 
72
73
  @parse_result.values
@@ -180,8 +181,7 @@ module URI
180
181
  elsif special_url? && c == "\\"
181
182
  @state = :relative_slash_state
182
183
  else
183
-
184
- @parse_result[:userinfo] = @base[:userinfo]
184
+ @username, @password = @base[:userinfo].split(":") if @base[:userinfo]
185
185
  @parse_result[:host] = @base[:host]
186
186
  @parse_result[:port] = @base[:port]
187
187
  @paths = @base_paths
@@ -208,7 +208,7 @@ module URI
208
208
  elsif c == "/"
209
209
  @state = :authority_state
210
210
  else
211
- @parse_result[:userinfo] = @base[:userinfo]
211
+ @username, @password = @base[:userinfo].split(":") if @base[:userinfo]
212
212
  @parse_result[:host] = @base[:host]
213
213
  @parse_result[:port] = @base[:port]
214
214
  @state = :path_state
@@ -498,6 +498,17 @@ module URI
498
498
  def rest
499
499
  @uri[@pos+1..]
500
500
  end
501
+
502
+ def convert_to_uri(uri)
503
+ if uri.is_a?(URI::Generic)
504
+ uri
505
+ elsif uri = String.try_convert(uri)
506
+ parse(uri)
507
+ else
508
+ raise ArgumentError,
509
+ "bad argument (expected URI object or URI string)"
510
+ end
511
+ end
501
512
  end
502
513
  end
503
514
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri-whatwg_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Yaginuma
@@ -63,6 +63,7 @@ files:
63
63
  - Rakefile
64
64
  - lib/uri/whatwg_parser.rb
65
65
  - lib/uri/whatwg_parser/error.rb
66
+ - lib/uri/whatwg_parser/generic.rb
66
67
  - lib/uri/whatwg_parser/host_parser.rb
67
68
  - lib/uri/whatwg_parser/parser_helper.rb
68
69
  - lib/uri/whatwg_parser/version.rb