protocol-url 0.17.0 → 0.18.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: b2aa761d6ff888e7d33270085ff84b2743230dec6a755450987a1f005b9ff124
4
- data.tar.gz: 1de5b782218b6c8d289704d7cfc953593cf5133e86fe7c55edbda8044a9e9b41
3
+ metadata.gz: '049540a7791381da861b94d6ed8e6b3e0ad751d3b176106f1c50a029aba36e32'
4
+ data.tar.gz: d6431de11836accc4318f01066b3c2431b9f26e349b46e77fcf9108da80cfb5e
5
5
  SHA512:
6
- metadata.gz: 58533d06cadb21b1f038b156a7bb7d0d0e39c503e8993bab5fd7c7811d2f03e13b8431aa97b5221e925cbabdbb75b1d0a95d58d57c5c29d701aa552c327c0568
7
- data.tar.gz: 5fce5dc33f50136790eff38c7a122e7041c0b06fa07ce2b1bfc41ade0568f352a731b26b233c9aa36b2d7ce460a0b1de32dfd9b68beed86213c123d5bd5676d8
6
+ metadata.gz: 27cee8571add43c57a7b0c2255d7f6a40566d1b44fe49b8ed73a7b06c50ef2d9d259eb951c0ffae7bce3c77f026fb193924f7eb003c85bfc61250661c2ed6135
7
+ data.tar.gz: ec74d61c74a06b318b9ff1b9ebcedb261bb90e0f80293b8def6e8d22efeef30db04ebc873e5546f746556312cd45cbeaa6c487893021c0b773a27990a3efd3d5
checksums.yaml.gz.sig CHANGED
Binary file
@@ -114,7 +114,8 @@ module Protocol
114
114
  end
115
115
 
116
116
  # Append the absolute URL to the given buffer.
117
- def append(buffer = String.new)
117
+ # @parameter explicit [Boolean] Ignored because absolute URLs are already lexically identifiable.
118
+ def append(buffer = String.new, explicit: false)
118
119
  buffer << @scheme << ":" if @scheme
119
120
  buffer << "//" << @authority if @authority
120
121
  super(buffer)
@@ -147,9 +148,8 @@ module Protocol
147
148
 
148
149
  # Absolute URLs cannot be made relative without comparing their origins.
149
150
  # @parameter base [Object] The ignored base URL or path.
150
- # @parameter explicit [Boolean] Ignored for absolute URLs.
151
151
  # @returns [self] This absolute URL.
152
- def relative_to(base, explicit: false)
152
+ def relative_to(base)
153
153
  return self
154
154
  end
155
155
 
@@ -170,9 +170,10 @@ module Protocol
170
170
 
171
171
  # Convert the URL to its string representation.
172
172
  #
173
+ # @parameter explicit [Boolean] Ignored because absolute URLs are already lexically identifiable.
173
174
  # @returns [String] The formatted absolute URL string.
174
- def to_s
175
- append
175
+ def to_s(explicit: false)
176
+ append(explicit: explicit)
176
177
  end
177
178
  end
178
179
  end
@@ -67,7 +67,6 @@ 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 `./`.
71
70
  # @returns [String] The relative path from `from` to `target`.
72
71
  #
73
72
  # @example Calculate relative path between pages.
@@ -77,8 +76,8 @@ module Protocol
77
76
  # @example Calculate relative path in same directory.
78
77
  # Path.relative("/docs/guide.html", "/docs/index.html")
79
78
  # # => "guide.html"
80
- def self.relative(target, from, explicit: false)
81
- return Path[target].relative(from, explicit: explicit).to_s
79
+ def self.relative(target, from)
80
+ return Path[target].relative(from).to_s
82
81
  end
83
82
 
84
83
  # Initialize a path from either its complete encoded representation or encoded segments.
@@ -358,9 +357,8 @@ module Protocol
358
357
  # Calculate this path relative to another path.
359
358
  #
360
359
  # @parameter from [String | Array(String) | Path] The source path.
361
- # @parameter explicit [Boolean] Whether same-directory paths should start with `./`.
362
360
  # @returns [Path] The relative path from `from` to this path.
363
- def relative(from, explicit: false)
361
+ def relative(from)
364
362
  target_segments = self.segments
365
363
  from_segments = Path[from].segments
366
364
 
@@ -388,9 +386,6 @@ module Protocol
388
386
  # An empty reference identifies the current document, so identify the current directory explicitly:
389
387
  if relative_segments == [""]
390
388
  relative_segments = [".", ""]
391
- elsif explicit && relative_segments.first != ".."
392
- # Identify same-directory references explicitly:
393
- relative_segments.unshift(".")
394
389
  elsif relative_segments.first&.include?(":")
395
390
  # A colon in the first segment would be interpreted as a URI scheme:
396
391
  relative_segments.unshift(".")
@@ -162,8 +162,9 @@ module Protocol
162
162
  # Append the reference to the given buffer.
163
163
  # Encodes the fragment; the path already retains its encoded structure.
164
164
  # Query strings are passed through as-is (they contain = and & which are valid syntax).
165
- def append(buffer = String.new)
166
- buffer << @path.encoded
165
+ # @parameter explicit [Boolean] Whether the result should be lexically identifiable as a URL in a mixed grammar.
166
+ def append(buffer = String.new, explicit: false)
167
+ append_path(buffer, explicit: explicit)
167
168
 
168
169
  if @query and !@query.empty?
169
170
  buffer << "?" << @query
@@ -138,16 +138,15 @@ 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 `./`.
142
141
  # @returns [Relative] The relative URL.
143
- def relative_to(base, explicit: false)
142
+ def relative_to(base)
144
143
  return self unless @path.absolute?
145
144
 
146
145
  if base.is_a?(Relative)
147
146
  base = base.path
148
147
  end
149
148
 
150
- return self.class.new(@path.relative(base, explicit: explicit), @query, @fragment)
149
+ return self.class.new(@path.relative(base), @query, @fragment)
151
150
  end
152
151
 
153
152
  # Normalize the encoded path and simplify its structure.
@@ -176,8 +175,9 @@ module Protocol
176
175
 
177
176
  # Append the relative URL to the given buffer.
178
177
  # The path, query, and fragment are expected to already be properly encoded.
179
- def append(buffer = String.new)
180
- buffer << @path.encoded
178
+ # @parameter explicit [Boolean] Whether the result should be lexically identifiable as a URL in a mixed grammar.
179
+ def append(buffer = String.new, explicit: false)
180
+ append_path(buffer, explicit: explicit)
181
181
 
182
182
  if @query and !@query.empty?
183
183
  buffer << "?" << @query
@@ -237,10 +237,13 @@ module Protocol
237
237
  end
238
238
 
239
239
  # Convert the URL to its string representation.
240
+ # When explicit, same-directory references start with `./` so they can be
241
+ # distinguished from non-URL values in a mixed grammar.
240
242
  #
243
+ # @parameter explicit [Boolean] Whether the result should be lexically identifiable as a URL in a mixed grammar.
241
244
  # @returns [String] The formatted URL string.
242
- def to_s
243
- append
245
+ def to_s(explicit: false)
246
+ append(explicit: explicit)
244
247
  end
245
248
 
246
249
  # Convert the URL to a JSON-compatible representation.
@@ -264,6 +267,16 @@ module Protocol
264
267
  "#<#{self.class} #{to_s}>"
265
268
  end
266
269
 
270
+ # Append the path, optionally identifying a relative URL explicitly.
271
+ private def append_path(buffer, explicit: false)
272
+ if explicit && @path.relative?
273
+ path = @path.encoded
274
+ buffer << "./" unless path.start_with?("./", "../")
275
+ end
276
+
277
+ buffer << @path.encoded
278
+ end
279
+
267
280
  end
268
281
  end
269
282
  end
@@ -7,6 +7,6 @@
7
7
  module Protocol
8
8
  # @namespace
9
9
  module URL
10
- VERSION = "0.17.0"
10
+ VERSION = "0.18.0"
11
11
  end
12
12
  end
data/readme.md CHANGED
@@ -34,6 +34,46 @@ 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.18.0
38
+
39
+ - Support explicit URL serialization for mixed grammars, and remove explicit prefixes from relative path calculation.
40
+
41
+ ### v0.17.0
42
+
43
+ - Add optional explicit `./` prefixes when generating same-directory relative URLs.
44
+
45
+ ### v0.16.0
46
+
47
+ - Preserve directory and file semantics when generating relative URL paths.
48
+
49
+ ### v0.15.0
50
+
51
+ - Add `Protocol::URL::Relative#relative_to` for expressing root-relative URLs relative to a base path.
52
+
53
+ ### v0.14.0
54
+
55
+ - Allow paths to compare with their encoded string representation.
56
+
57
+ ### v0.13.0
58
+
59
+ - Add conservative normalization of encoded URL paths.
60
+
61
+ ### v0.12.0
62
+
63
+ - Allow unfrozen relative and absolute URLs to replace their components.
64
+
65
+ ### v0.10.0
66
+
67
+ - Rename `Protocol::URL::FormData::Parser::CONTENT_TYPE` to `MEDIA_TYPE`.
68
+
69
+ ### v0.9.0
70
+
71
+ - Add `Protocol::URL::LimitError` for configured processing limits.
72
+
73
+ ### v0.8.0
74
+
75
+ - Use consistent limit naming for form data parser constraints.
76
+
37
77
  ### v0.17.0
38
78
 
39
79
  - Add optional explicit `./` prefixes when generating same-directory relative URLs.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.18.0
4
+
5
+ - Support explicit URL serialization for mixed grammars, and remove explicit prefixes from relative path calculation.
6
+
3
7
  ## v0.17.0
4
8
 
5
9
  - Add optional explicit `./` prefixes when generating same-directory relative URLs.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file