http-negotiate 0.2.0 → 0.2.2

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: 6c40df3f0c699e99b0f45c3af71e19e5461878bddecf1a8a28a4125965cc05c9
4
- data.tar.gz: 58dfdd11e0a9b119f5e84bdb24e8d2d28145e91d7a8fa3d5d3067572d1c2980e
3
+ metadata.gz: d699dd657fff5ae1a330a54f83b33b9d091a455e052566270e3ff697e4eedc97
4
+ data.tar.gz: baae101cbbe136cf67f698eb4fb6990fc43e6194f4dbebcd7acc786911ec5c2d
5
5
  SHA512:
6
- metadata.gz: 0610a598b694dfa3a147257e160dfbfafcde951715ff7329f489b22e097490e2999f84a8401ef6019183f30fbbdbe01c31c4daf7dd9abcab34402add0a1f96bc
7
- data.tar.gz: b3a19ba49afe90cd32aba42046ec57af147bb1a12f7087102fed03e5520c30cc33fecc41785a226cf7a5680298adcb59ea2b14a9bcd6950db3b2148109a070be
6
+ metadata.gz: ef0b67b2cb482168f9effe5900efb1f1be8c24a42fde4ddb3d51669b950d63e42f651c5b5cd6062172dff940ad4b27741b24648560a7d72343354969bdb7bafb
7
+ data.tar.gz: bd297a0bb246293fb405da83eafdf5226ffd38aedabf648c1d88234177c12a63a59e9cdb0ca7dc6e0462b0a1c4ac55707ffa0a8a4fd6cbe74fc53f0dd0ebec42
@@ -1,5 +1,5 @@
1
1
  module HTTP
2
2
  module Negotiate
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
@@ -55,18 +55,19 @@ module HTTP::Negotiate
55
55
  # theoretically you can have quoted-string parameter values
56
56
  # but we don't care (although interestingly according to rfc7231,
57
57
  # accept-language only affords q= and not arbitrary parameters)
58
- hdr = hdr.dup.gsub(/\s+/, '')
58
+ hdr = hdr.respond_to?(:to_a) ? hdr.to_a.dup : hdr.to_s.split(/\s*,+\s*/)
59
+ hdr = hdr.map { |h| h.to_s.gsub(/\s+/, '') }.reject(&:empty?)
59
60
 
60
61
  # don't add the test group if it's an empty string, because
61
62
  # postel's law is a thing
62
63
  next if hdr.empty?
63
64
 
64
- accept[k] = hdr.split(/,+/).map do |c|
65
+ accept[k] = hdr.map do |c|
65
66
  val, *params = c.split(/;+/)
66
67
  params = params.map do |p|
67
- k, v = p.split(/=+/, 2)
68
+ k, v = p.split(/\s*=+\s*/, 2)
68
69
  k = k.downcase.to_sym
69
- v = v.to_f if v and k == :q
70
+ v = v.to_f if v and k == :q # note garbage will return 0
70
71
  [k, v]
71
72
  end.to_h
72
73
  if params[:q]
@@ -228,12 +229,14 @@ module HTTP::Negotiate
228
229
  else
229
230
  0.1
230
231
  end
231
-
232
232
  end
233
233
 
234
234
  scores[var] = [qs * qe * qc * ql * qt, size]
235
235
  end
236
236
 
237
+ # DUH DON'T FORGET TO NUKE THE ZERO SCORES
238
+ scores.reject! { |_, s| s.first == 0 }
239
+
237
240
  # XXX do something smarter here for secondary comparison
238
241
  cmp ||= -> a, b { 0 }
239
242
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-negotiate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-23 00:00:00.000000000 Z
11
+ date: 2024-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler