berkeley_library-util 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81d92682b9ea2f5466198ab26b0a31775704f3d52408e67453b1af8871367aa8
4
- data.tar.gz: 296f6fd7ad69c125e732b423f9eb75f338cc866b9a7c19dae6c550d754a2c285
3
+ metadata.gz: fdc84acc6adb94fcfbbcf7d18b9a6bead8ef484ef40028f139b07964b565b4e2
4
+ data.tar.gz: 43e850e1ee541d777c07f546f789e576b45a44580734206c44cd2dce4d3293a1
5
5
  SHA512:
6
- metadata.gz: f632ee12e255ca16fcd22effc3df7d1ddcf7cb4a93ac49c4ca7d3beef8ba29143b8bc1f96097236fdf9dde1802625423990052ac12a4920cb0e8a074715b3cf4
7
- data.tar.gz: c9ab1aa8a055caf6ba968af662fdcf3dbe782fdce4c0e884032db10a427dae4049f48fde9297d415336374760183ec23058c355bed3ee8bb9f90593bf3844841
6
+ metadata.gz: dc47ba39cee501522db01aceeba7060f51ee4270ca03a2d4263e836190eddc2e953fd83eb292379ce4fcdbd5a9bac3831ec76c750cb2ecd9a375c86a60533079
7
+ data.tar.gz: 0dc4190292083d68066528c6a7efa815667ccc6ba79fb75ba0d0fa5e5f1ab354465447d1d7b53bbf825426e010bd4954b0ada17f3b935ae68095d8d0795940c1
@@ -11,7 +11,7 @@ jobs:
11
11
 
12
12
  steps:
13
13
  - name: Check out repository
14
- uses: actions/checkout@v2
14
+ uses: actions/checkout@v3
15
15
 
16
16
  - name: Set up Ruby
17
17
  uses: ruby/setup-ruby@v1
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.1.9 (2023-06-01)
2
+
3
+ - `URIs#path_escape` now attempts to convert non-UTF-8 strings to UTF-8 rather than immediately
4
+ raising an error.
5
+
1
6
  # 0.1.8 (2023-03-20)
2
7
 
3
8
  - Add `Retry-After` support to `Requester` for `429 Too Many Requests` and `503 Service Unavailable`.
@@ -7,7 +7,7 @@ module BerkeleyLibrary
7
7
  SUMMARY = 'Miscellaneous Ruby utilities for the UC Berkeley Library'.freeze
8
8
  DESCRIPTION = 'A collection of miscellaneous Ruby routines for the UC Berkeley Library.'.freeze
9
9
  LICENSE = 'MIT'.freeze
10
- VERSION = '0.1.8'.freeze
10
+ VERSION = '0.1.9'.freeze
11
11
  HOMEPAGE = 'https://github.com/BerkeleyLibrary/util'.freeze
12
12
  end
13
13
  end
@@ -88,8 +88,8 @@ module BerkeleyLibrary
88
88
  # replacing disallowed characters (including /) with percent-encodings as needed.
89
89
  def path_escape(s)
90
90
  raise ArgumentError, "Can't escape #{s.inspect}: not a string" unless s.respond_to?(:encoding)
91
- raise ArgumentError, "Can't escape #{s.inspect}: expected #{UTF_8}, was #{s.encoding}" unless s.encoding == UTF_8
92
91
 
92
+ s = s.encode(UTF_8) unless s.encoding == UTF_8
93
93
  ''.tap do |escaped|
94
94
  s.bytes.each do |b|
95
95
  escaped << (should_escape?(b, :path_segment) ? '%%%02X' % b : b.chr)
@@ -101,7 +101,7 @@ module BerkeleyLibrary
101
101
  end
102
102
 
103
103
  it 'raises RetryDelayTooLarge if the delay is too large' do
104
- retry_after_seconds = 1 + BerkeleyLibrary::Util::URIs::Requester::MAX_RETRY_DELAY_SECONDS
104
+ retry_after_seconds = 10 + BerkeleyLibrary::Util::URIs::Requester::MAX_RETRY_DELAY_SECONDS
105
105
 
106
106
  stub_request(:get, url)
107
107
  .to_return(status: 429, headers: { 'Retry-After' => retry_after_seconds.to_s })
@@ -163,7 +163,7 @@ module BerkeleyLibrary
163
163
  end
164
164
 
165
165
  it 'raises RetryDelayTooLarge if the delay is too large' do
166
- retry_after_seconds = 1 + BerkeleyLibrary::Util::URIs::Requester::MAX_RETRY_DELAY_SECONDS
166
+ retry_after_seconds = 10 + BerkeleyLibrary::Util::URIs::Requester::MAX_RETRY_DELAY_SECONDS
167
167
  retry_after_datetime = (Time.now + retry_after_seconds)
168
168
 
169
169
  stub_request(:get, url)
@@ -236,7 +236,7 @@ module BerkeleyLibrary
236
236
  end
237
237
 
238
238
  it 'raises RetryDelayTooLarge if the delay is too large' do
239
- retry_after_seconds = 1 + BerkeleyLibrary::Util::URIs::Requester::MAX_RETRY_DELAY_SECONDS
239
+ retry_after_seconds = 10 + BerkeleyLibrary::Util::URIs::Requester::MAX_RETRY_DELAY_SECONDS
240
240
 
241
241
  stub_request(:get, url)
242
242
  .to_return(status: 503, headers: { 'Retry-After' => retry_after_seconds.to_s })
@@ -283,7 +283,7 @@ module BerkeleyLibrary
283
283
  end
284
284
 
285
285
  it 'raises RetryDelayTooLarge if the delay is too large' do
286
- retry_after_seconds = 1 + BerkeleyLibrary::Util::URIs::Requester::MAX_RETRY_DELAY_SECONDS
286
+ retry_after_seconds = 10 + BerkeleyLibrary::Util::URIs::Requester::MAX_RETRY_DELAY_SECONDS
287
287
  retry_after_datetime = (Time.now + retry_after_seconds)
288
288
 
289
289
  stub_request(:get, url)
@@ -337,20 +337,14 @@ module BerkeleyLibrary::Util
337
337
  expect { URIs.path_escape(str.bytes) }.to raise_error(ArgumentError)
338
338
  end
339
339
 
340
- it 'rejects non-UTF-8 strings' do
341
- str = in_out.keys.last
342
- expect { URIs.path_escape(str.encode(Encoding::Shift_JIS)) }.to raise_error(ArgumentError)
343
- end
344
-
345
- it 'accepts non-UTF-8 strings converted to UTF-8' do
346
- in_str = in_out.keys.last
347
- out_str = in_out[in_str]
348
-
349
- # OK, we're really just testing String#encode here, but
350
- # it's useful for documentation
351
- in_str_sjis = in_str.encode(Encoding::Shift_JIS)
352
- in_str_utf8 = in_str_sjis.encode(Encoding::UTF_8)
353
- expect(URIs.path_escape(in_str_utf8)).to eq(out_str)
340
+ it 'converts non-UTF-8 strings to UTF-8' do
341
+ utf_16_be = Encoding.find('UTF-16BE')
342
+ aggregate_failures do
343
+ in_out.each do |in_str, out_str|
344
+ encoded = in_str.encode(utf_16_be)
345
+ expect(URIs.path_escape(encoded)).to eq(out_str)
346
+ end
347
+ end
354
348
  end
355
349
  end
356
350
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkeley_library-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-20 00:00:00.000000000 Z
11
+ date: 2023-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: berkeley_library-logging