protocol-url 0.15.0 → 0.17.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
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/url/absolute.rb +2 -1
- data/lib/protocol/url/path.rb +21 -3
- data/lib/protocol/url/relative.rb +3 -2
- data/lib/protocol/url/version.rb +1 -1
- data/readme.md +81 -0
- data/releases.md +8 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b2aa761d6ff888e7d33270085ff84b2743230dec6a755450987a1f005b9ff124
|
|
4
|
+
data.tar.gz: 1de5b782218b6c8d289704d7cfc953593cf5133e86fe7c55edbda8044a9e9b41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58533d06cadb21b1f038b156a7bb7d0d0e39c503e8993bab5fd7c7811d2f03e13b8431aa97b5221e925cbabdbb75b1d0a95d58d57c5c29d701aa552c327c0568
|
|
7
|
+
data.tar.gz: 5fce5dc33f50136790eff38c7a122e7041c0b06fa07ce2b1bfc41ade0568f352a731b26b233c9aa36b2d7ce460a0b1de32dfd9b68beed86213c123d5bd5676d8
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -147,8 +147,9 @@ module Protocol
|
|
|
147
147
|
|
|
148
148
|
# Absolute URLs cannot be made relative without comparing their origins.
|
|
149
149
|
# @parameter base [Object] The ignored base URL or path.
|
|
150
|
+
# @parameter explicit [Boolean] Ignored for absolute URLs.
|
|
150
151
|
# @returns [self] This absolute URL.
|
|
151
|
-
def relative_to(base)
|
|
152
|
+
def relative_to(base, explicit: false)
|
|
152
153
|
return self
|
|
153
154
|
end
|
|
154
155
|
|
data/lib/protocol/url/path.rb
CHANGED
|
@@ -67,6 +67,7 @@ module Protocol
|
|
|
67
67
|
#
|
|
68
68
|
# @parameter target [String] The destination path (where you want to go).
|
|
69
69
|
# @parameter from [String] The source path (where you are starting from).
|
|
70
|
+
# @parameter explicit [Boolean] Whether same-directory paths should start with `./`.
|
|
70
71
|
# @returns [String] The relative path from `from` to `target`.
|
|
71
72
|
#
|
|
72
73
|
# @example Calculate relative path between pages.
|
|
@@ -76,8 +77,8 @@ module Protocol
|
|
|
76
77
|
# @example Calculate relative path in same directory.
|
|
77
78
|
# Path.relative("/docs/guide.html", "/docs/index.html")
|
|
78
79
|
# # => "guide.html"
|
|
79
|
-
def self.relative(target, from)
|
|
80
|
-
return Path[target].relative(from).to_s
|
|
80
|
+
def self.relative(target, from, explicit: false)
|
|
81
|
+
return Path[target].relative(from, explicit: explicit).to_s
|
|
81
82
|
end
|
|
82
83
|
|
|
83
84
|
# Initialize a path from either its complete encoded representation or encoded segments.
|
|
@@ -357,8 +358,9 @@ module Protocol
|
|
|
357
358
|
# Calculate this path relative to another path.
|
|
358
359
|
#
|
|
359
360
|
# @parameter from [String | Array(String) | Path] The source path.
|
|
361
|
+
# @parameter explicit [Boolean] Whether same-directory paths should start with `./`.
|
|
360
362
|
# @returns [Path] The relative path from `from` to this path.
|
|
361
|
-
def relative(from)
|
|
363
|
+
def relative(from, explicit: false)
|
|
362
364
|
target_segments = self.segments
|
|
363
365
|
from_segments = Path[from].segments
|
|
364
366
|
|
|
@@ -372,12 +374,28 @@ module Protocol
|
|
|
372
374
|
common_length = i + 1
|
|
373
375
|
end
|
|
374
376
|
|
|
377
|
+
# Preserve the final segment when the target names the containing directory as a file:
|
|
378
|
+
if common_length > 0 && common_length == target_segments.size && target_segments.last != ""
|
|
379
|
+
common_length -= 1
|
|
380
|
+
end
|
|
381
|
+
|
|
375
382
|
# Calculate how many levels to go up
|
|
376
383
|
up_levels = from_segments.size - common_length
|
|
377
384
|
|
|
378
385
|
# Build the relative path segments
|
|
379
386
|
relative_segments = [".."] * up_levels + target_segments[common_length..-1]
|
|
380
387
|
|
|
388
|
+
# An empty reference identifies the current document, so identify the current directory explicitly:
|
|
389
|
+
if relative_segments == [""]
|
|
390
|
+
relative_segments = [".", ""]
|
|
391
|
+
elsif explicit && relative_segments.first != ".."
|
|
392
|
+
# Identify same-directory references explicitly:
|
|
393
|
+
relative_segments.unshift(".")
|
|
394
|
+
elsif relative_segments.first&.include?(":")
|
|
395
|
+
# A colon in the first segment would be interpreted as a URI scheme:
|
|
396
|
+
relative_segments.unshift(".")
|
|
397
|
+
end
|
|
398
|
+
|
|
381
399
|
return Path.new(nil, relative_segments)
|
|
382
400
|
end
|
|
383
401
|
|
|
@@ -138,15 +138,16 @@ module Protocol
|
|
|
138
138
|
# are preserved when converting a root-relative path.
|
|
139
139
|
#
|
|
140
140
|
# @parameter base [Relative | Path | String] The base URL or path.
|
|
141
|
+
# @parameter explicit [Boolean] Whether same-directory paths should start with `./`.
|
|
141
142
|
# @returns [Relative] The relative URL.
|
|
142
|
-
def relative_to(base)
|
|
143
|
+
def relative_to(base, explicit: false)
|
|
143
144
|
return self unless @path.absolute?
|
|
144
145
|
|
|
145
146
|
if base.is_a?(Relative)
|
|
146
147
|
base = base.path
|
|
147
148
|
end
|
|
148
149
|
|
|
149
|
-
return self.class.new(@path.relative(base), @query, @fragment)
|
|
150
|
+
return self.class.new(@path.relative(base, explicit: explicit), @query, @fragment)
|
|
150
151
|
end
|
|
151
152
|
|
|
152
153
|
# Normalize the encoded path and simplify its structure.
|
data/lib/protocol/url/version.rb
CHANGED
data/readme.md
CHANGED
|
@@ -34,6 +34,87 @@ bundle exec sus
|
|
|
34
34
|
|
|
35
35
|
Please see the [project releases](https://socketry.github.io/protocol-url/releases/index) for all releases.
|
|
36
36
|
|
|
37
|
+
### v0.17.0
|
|
38
|
+
|
|
39
|
+
- Add optional explicit `./` prefixes when generating same-directory relative URLs.
|
|
40
|
+
|
|
41
|
+
### v0.16.0
|
|
42
|
+
|
|
43
|
+
- Preserve directory and file semantics when generating relative URL paths.
|
|
44
|
+
|
|
45
|
+
### v0.15.0
|
|
46
|
+
|
|
47
|
+
- Add `Protocol::URL::Relative#relative_to` for expressing root-relative URLs relative to a base path.
|
|
48
|
+
|
|
49
|
+
### v0.14.0
|
|
50
|
+
|
|
51
|
+
- Allow paths to compare with their encoded string representation.
|
|
52
|
+
|
|
53
|
+
### v0.13.0
|
|
54
|
+
|
|
55
|
+
- Add conservative normalization of encoded URL paths.
|
|
56
|
+
|
|
57
|
+
### v0.12.0
|
|
58
|
+
|
|
59
|
+
- Allow unfrozen relative and absolute URLs to replace their components.
|
|
60
|
+
|
|
61
|
+
### v0.10.0
|
|
62
|
+
|
|
63
|
+
- Rename `Protocol::URL::FormData::Parser::CONTENT_TYPE` to `MEDIA_TYPE`.
|
|
64
|
+
|
|
65
|
+
### v0.9.0
|
|
66
|
+
|
|
67
|
+
- Add `Protocol::URL::LimitError` for configured processing limits.
|
|
68
|
+
|
|
69
|
+
### v0.8.0
|
|
70
|
+
|
|
71
|
+
- Use consistent limit naming for form data parser constraints.
|
|
72
|
+
|
|
73
|
+
### v0.7.0
|
|
74
|
+
|
|
75
|
+
- Allow `Protocol::URL::FormData::Parser#parse` to populate a supplied result object.
|
|
76
|
+
|
|
77
|
+
### v0.16.0
|
|
78
|
+
|
|
79
|
+
- Preserve directory and file semantics when generating relative URL paths.
|
|
80
|
+
|
|
81
|
+
### v0.15.0
|
|
82
|
+
|
|
83
|
+
- Add `Protocol::URL::Relative#relative_to` for expressing root-relative URLs relative to a base path.
|
|
84
|
+
|
|
85
|
+
### v0.14.0
|
|
86
|
+
|
|
87
|
+
- Allow paths to compare with their encoded string representation.
|
|
88
|
+
|
|
89
|
+
### v0.13.0
|
|
90
|
+
|
|
91
|
+
- Add conservative normalization of encoded URL paths.
|
|
92
|
+
|
|
93
|
+
### v0.12.0
|
|
94
|
+
|
|
95
|
+
- Allow unfrozen relative and absolute URLs to replace their components.
|
|
96
|
+
|
|
97
|
+
### v0.10.0
|
|
98
|
+
|
|
99
|
+
- Rename `Protocol::URL::FormData::Parser::CONTENT_TYPE` to `MEDIA_TYPE`.
|
|
100
|
+
|
|
101
|
+
### v0.9.0
|
|
102
|
+
|
|
103
|
+
- Add `Protocol::URL::LimitError` for configured processing limits.
|
|
104
|
+
|
|
105
|
+
### v0.8.0
|
|
106
|
+
|
|
107
|
+
- Use consistent limit naming for form data parser constraints.
|
|
108
|
+
|
|
109
|
+
### v0.7.0
|
|
110
|
+
|
|
111
|
+
- Allow `Protocol::URL::FormData::Parser#parse` to populate a supplied result object.
|
|
112
|
+
|
|
113
|
+
### v0.6.0
|
|
114
|
+
|
|
115
|
+
- Add `Protocol::URL::FormData::Parser` for incremental, limited parsing of `application/x-www-form-urlencoded` form data.
|
|
116
|
+
- Add `Protocol::URL::FormData::Nested` for consistently building nested form data while preserving absent and empty values.
|
|
117
|
+
|
|
37
118
|
### v0.15.0
|
|
38
119
|
|
|
39
120
|
- Add `Protocol::URL::Relative#relative_to` for expressing root-relative URLs relative to a base path.
|
data/releases.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
+
## v0.17.0
|
|
4
|
+
|
|
5
|
+
- Add optional explicit `./` prefixes when generating same-directory relative URLs.
|
|
6
|
+
|
|
7
|
+
## v0.16.0
|
|
8
|
+
|
|
9
|
+
- Preserve directory and file semantics when generating relative URL paths.
|
|
10
|
+
|
|
3
11
|
## v0.15.0
|
|
4
12
|
|
|
5
13
|
- Add `Protocol::URL::Relative#relative_to` for expressing root-relative URLs relative to a base path.
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|