philiprehberger-uri_kit 0.4.0 → 0.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +13 -0
- data/lib/philiprehberger/uri_kit/version.rb +1 -1
- data/lib/philiprehberger/uri_kit.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a3d717ecc7eb545cb2ad756547396511336bfcc89083b76d181e8354493ef34c
|
|
4
|
+
data.tar.gz: 91ec82b51e7b0f600f728778eef697554c532c920c90ae85bd1c2e60dd65eb02
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4dc751bd3bb540cf390922148c1e903a0a729ee86ea45fcb2b9b379ede8666a0fecc62375eb4160e129094f208614d26f17cdc8c27e2e22b5f6c9bd59648233
|
|
7
|
+
data.tar.gz: a118d5b646e36d16eb6dfad46084acd740b3c17ef47b8d7af606e0e975c6c9b4e3b53d0654d81cc62a257f9091ab38c82eb38403addaf50a93c08b9d1a4d423e
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-04-25
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Url#same_origin?(other)` for RFC 6454 same-origin checks (scheme, host, effective port)
|
|
14
|
+
- `Url#same_host?(other)` for case-insensitive host-only comparison
|
|
15
|
+
|
|
10
16
|
## [0.4.0] - 2026-04-20
|
|
11
17
|
|
|
12
18
|
### Added
|
data/README.md
CHANGED
|
@@ -129,6 +129,17 @@ url = Philiprehberger::UriKit.join('https://example.com/base/', 'page.html')
|
|
|
129
129
|
url.to_s # => "https://example.com/base/page.html"
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
+
### Origin and Host Comparison
|
|
133
|
+
|
|
134
|
+
```ruby
|
|
135
|
+
require "philiprehberger/uri_kit"
|
|
136
|
+
|
|
137
|
+
a = Philiprehberger::UriKit.parse('https://example.com/page')
|
|
138
|
+
b = Philiprehberger::UriKit.parse('https://example.com/other')
|
|
139
|
+
a.same_origin?(b) # => true
|
|
140
|
+
a.same_host?('http://example.com') # => true
|
|
141
|
+
```
|
|
142
|
+
|
|
132
143
|
## API
|
|
133
144
|
|
|
134
145
|
| Method | Description |
|
|
@@ -157,6 +168,8 @@ url.to_s # => "https://example.com/base/page.html"
|
|
|
157
168
|
| `Url#fragment` | Fragment identifier |
|
|
158
169
|
| `Url#to_s` | Get the full URL string |
|
|
159
170
|
| `Url#==` / `Url#eql?` | Value equality based on string representation |
|
|
171
|
+
| `Url#same_origin?(other)` | True when scheme, host, and effective port match (RFC 6454) |
|
|
172
|
+
| `Url#same_host?(other)` | True when only the host matches, case-insensitive |
|
|
160
173
|
|
|
161
174
|
## Development
|
|
162
175
|
|
|
@@ -206,6 +206,39 @@ module Philiprehberger
|
|
|
206
206
|
to_s.hash
|
|
207
207
|
end
|
|
208
208
|
|
|
209
|
+
# Same origin per RFC 6454: identical scheme, host (case-insensitive), and
|
|
210
|
+
# effective port. Default ports (80 for http, 443 for https) are treated as
|
|
211
|
+
# equal to no port.
|
|
212
|
+
#
|
|
213
|
+
# @param other [Url, String]
|
|
214
|
+
# @return [Boolean]
|
|
215
|
+
def same_origin?(other)
|
|
216
|
+
other = self.class.new(other) if other.is_a?(String)
|
|
217
|
+
return false unless other.is_a?(self.class)
|
|
218
|
+
|
|
219
|
+
scheme.to_s.downcase == other.scheme.to_s.downcase &&
|
|
220
|
+
host.to_s.downcase == other.host.to_s.downcase &&
|
|
221
|
+
effective_port == other.effective_port
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Same host (case-insensitive). Ignores scheme, port, path, and query.
|
|
225
|
+
#
|
|
226
|
+
# @param other [Url, String]
|
|
227
|
+
# @return [Boolean]
|
|
228
|
+
def same_host?(other)
|
|
229
|
+
other = self.class.new(other) if other.is_a?(String)
|
|
230
|
+
return false unless other.is_a?(self.class)
|
|
231
|
+
|
|
232
|
+
host.to_s.downcase == other.host.to_s.downcase
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
protected
|
|
236
|
+
|
|
237
|
+
def effective_port
|
|
238
|
+
default = { 'http' => 80, 'https' => 443, 'ws' => 80, 'wss' => 443 }
|
|
239
|
+
port || default[scheme.to_s.downcase]
|
|
240
|
+
end
|
|
241
|
+
|
|
209
242
|
private
|
|
210
243
|
|
|
211
244
|
def encode_params(hash)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-uri_kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Parse, build, and manipulate URLs with query parameter management, normalization,
|
|
14
14
|
domain extraction, and URL joining. Built on Ruby stdlib URI.
|