stduritemplate 0.0.49 → 0.0.52

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stduritemplate.rb +22 -11
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f74c3bfb52bab5f58e7bfa30e4a063c51a4c3d86c412eaf9e69c647d979256d0
4
- data.tar.gz: f0c7dbef8bcc7b91af8e281c8bdee4399928ec78e5686d1a1be89499f95a2402
3
+ metadata.gz: cf0bbba2eb1fd6a23888deb9e842be7e8b310c47153fe276d055ab7e42ec1864
4
+ data.tar.gz: e6b8ee16919e646d6c8aa788533cd179eae6dc9c52a64ad3c046e67efc709ce7
5
5
  SHA512:
6
- metadata.gz: 32b5c55e41e60eb7c86982c96145fbce95887c39be1beafe68bbdcf7d63278a2cf140c662a9a567222bd9efbab8499e77b196b878d3d35d6b179496bc635c2bc
7
- data.tar.gz: b3c50bbe68341d4d2aa8a68fd12c5e8a0b40a6bbae5987949c6753f064f79b6843121db6b7319f638b3dc90e1c12c1920045e274dbd376146765c29643f9f092
6
+ metadata.gz: f1119ccf5ae3ca0b425026896fd6db74bae3df0842cf8cd3b7f83572e3f20e604ca74e73d916d0108359795d14ba15416a8970b2e1739c5f2447c8e3e461d8a3
7
+ data.tar.gz: 10bd3997b3b7e42a64fbf8e8b932f418c207df9ee3cc81251451a40a75752ca3b344e8e6b3a16aae8565a6736700837c0c52b6f99bce638d7850592292299e73
@@ -188,6 +188,20 @@ module StdUriTemplate
188
188
  end
189
189
  end
190
190
 
191
+ def self.is_surrogate(cp)
192
+ cp.bytes.length > 1
193
+ end
194
+
195
+ def self.is_iprivate(cp)
196
+ (0xE000..0xF8FF).include?(cp.ord)
197
+ end
198
+
199
+ def self.is_ucschar(cp)
200
+ (0xA0..0xD7FF).include?(cp.ord) ||
201
+ (0xF900..0xFDCF).include?(cp.ord) ||
202
+ (0xFDF0..0xFFEF).include?(cp.ord)
203
+ end
204
+
191
205
  def self.add_expanded_value(prefix, value, result, max_char, replace_reserved)
192
206
  string_value = convert_native_types(value)
193
207
  max = (max_char != -1) ? [max_char, string_value.length].min : string_value.length
@@ -204,8 +218,13 @@ module StdUriTemplate
204
218
  reserved_buffer = ''
205
219
  end
206
220
 
221
+ to_append = character
222
+ if is_surrogate(character) || replace_reserved || is_ucschar(character) || is_iprivate(character)
223
+ to_append = URI.encode_www_form_component(character)
224
+ end
225
+
207
226
  if reserved_buffer
208
- reserved_buffer << character
227
+ reserved_buffer << to_append
209
228
 
210
229
  if reserved_buffer.length == 3
211
230
  is_encoded = false
@@ -230,22 +249,14 @@ module StdUriTemplate
230
249
  elsif character == '%'
231
250
  result << "%25"
232
251
  else
233
- if replace_reserved
234
- result << URI.encode_www_form_component(character)
235
- else
236
- result << character
237
- end
252
+ result << to_append
238
253
  end
239
254
  end
240
255
  end
241
256
 
242
257
  if reserved_buffer
243
258
  result << "%25"
244
- if replace_reserved
245
- result << URI.encode_www_form_component(reserved_buffer[1..-1])
246
- else
247
- result << reserved_buffer[1..-1]
248
- end
259
+ result << reserved_buffer[1..-1]
249
260
  end
250
261
  end
251
262
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stduritemplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.49
4
+ version: 0.0.52
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Peruffo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-12 00:00:00.000000000 Z
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: std-uritemplate implementation for Ruby
14
14
  email: andrea.peruffo1982@gmail.com