nokogiri-html-ext 1.4.0 → 1.5.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
  SHA256:
3
- metadata.gz: 81844b7536086078b24d1600282bb324c1325cc62b527b45bf81a13090ff413a
4
- data.tar.gz: fdda5725873079052a6315c6d19a388dce12586c54ed88cb42321f215f2826fe
3
+ metadata.gz: fe48e23deb7150b7adf50eb5298dfef2dbc9a75898574ed21cd567038728d2ed
4
+ data.tar.gz: 0f5f378ae1180ab2718b1927e220d092363a8cb013766e4ffaf483050c2f7020
5
5
  SHA512:
6
- metadata.gz: 307a4c317c840578338d253d1c6c8586ab863ec97f32cde0339069c8a096220c6863d718d305f000357cee68fdfb4e5b36e7cc8a91eb27e7bcd55045b7cf7a77
7
- data.tar.gz: d1701b55fe58d9b80378b2a9b09a5c73a0c528895869aa99ecd01ce6d4b291c6108708b5eb6ea55c1201e545c975e85af14489b58272282473451b27a4c2e929
6
+ metadata.gz: beba250e78b23dfea02fe3cdbca224049f4a63f7f6ab990403eedaab6d29770f09aaa47fa2cadc18304237baa2b9b2d751a2940b6d34e98a9b3abd48f815e02e
7
+ data.tar.gz: 2971a2ae956f0877aae05a70ea6283ccebb72c935667deda53d7337f4cde74b946950ce0a2f826a7a522c7538ddf84090603a683690baf080238709a705f0dd8
@@ -56,31 +56,31 @@ module Nokogiri
56
56
  base["href"] = url
57
57
  end
58
58
 
59
- # Convert a relative URL to an absolute URL based on the current document.
59
+ # Resolve a URL based on the current document.
60
60
  #
61
61
  # @param url [String]
62
62
  #
63
63
  # @return [String]
64
- def resolve_relative_url(url)
65
- strs = [document.url, base_href, url].compact
64
+ def resolve_url(url)
65
+ uris = [document.url, base_href, url].filter_map { |uri| Addressable::URI.parse(uri&.strip) }
66
66
 
67
- Addressable::URI.join(*strs).to_s
67
+ return uris.last.to_s if uris.last.absolute?
68
+
69
+ Addressable::URI.join(*uris).to_s
68
70
  rescue Addressable::URI::InvalidURIError
69
71
  url
70
72
  end
71
73
 
72
- # Convert the document's relative URLs to absolute URLs.
74
+ # Resolve the document's URLs
73
75
  #
74
76
  # @return [self]
75
- def resolve_relative_urls!
77
+ def resolve_urls!
76
78
  xpath(*ATTRIBUTES_XPATHS).each do |attr_node|
77
- stripped_value = attr_node.value.strip
78
-
79
79
  attr_node.value =
80
80
  if SRCSET_ATTRIBUTES_MAP.key?(attr_node.name)
81
- resolve_srcset_attributes(stripped_value.split(/\s*,\s*/))
81
+ resolve_srcset_attributes(attr_node.value.split(/\s*,\s*/))
82
82
  else
83
- resolve_relative_url(stripped_value)
83
+ resolve_url(attr_node.value)
84
84
  end
85
85
  end
86
86
 
@@ -98,7 +98,7 @@ module Nokogiri
98
98
  def resolve_srcset_attributes(srcset_attributes)
99
99
  srcset_attributes.map! do |candidate_string|
100
100
  # rubocop:disable Style/PerlBackrefs
101
- candidate_string.sub(/^(.+?)(\s+.+)?$/) { "#{resolve_relative_url($1)}#{$2}" }
101
+ candidate_string.sub(/^(.+?)(\s+.+)?$/) { "#{resolve_url($1)}#{$2}" }
102
102
  # rubocop:enable Style/PerlBackrefs
103
103
  end
104
104
 
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
4
4
  spec.required_ruby_version = ">= 2.7"
5
5
 
6
6
  spec.name = "nokogiri-html-ext"
7
- spec.version = "1.4.0"
7
+ spec.version = "1.5.0"
8
8
  spec.authors = ["Jason Garber"]
9
9
  spec.email = ["jason@sixtwothree.org"]
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri-html-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
@@ -55,11 +55,11 @@ licenses:
55
55
  - MIT
56
56
  metadata:
57
57
  bug_tracker_uri: https://codeberg.org/jgarber/nokogiri-html-ext/issues
58
- changelog_uri: https://codeberg.org/jgarber/nokogiri-html-ext/releases/tag/v1.4.0
59
- documentation_uri: https://rubydoc.info/gems/nokogiri-html-ext/1.4.0
58
+ changelog_uri: https://codeberg.org/jgarber/nokogiri-html-ext/releases/tag/v1.5.0
59
+ documentation_uri: https://rubydoc.info/gems/nokogiri-html-ext/1.5.0
60
60
  homepage_uri: https://codeberg.org/jgarber/nokogiri-html-ext
61
61
  rubygems_mfa_required: 'true'
62
- source_code_uri: https://codeberg.org/jgarber/nokogiri-html-ext/src/tag/v1.4.0
62
+ source_code_uri: https://codeberg.org/jgarber/nokogiri-html-ext/src/tag/v1.5.0
63
63
  rdoc_options: []
64
64
  require_paths:
65
65
  - lib
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubygems_version: 3.6.8
77
+ rubygems_version: 3.6.9
78
78
  specification_version: 4
79
79
  summary: Extend Nokogiri with several useful HTML-centric features.
80
80
  test_files: []