http-accept 2.2.1 → 2.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: 744d60056b2386b45fad957f49be310a0672f276cb5528fbea605ca28759f332
4
- data.tar.gz: 64a14c45a36902a23b639b0be824351ad89afb8a4f8dd8180e6b15d2539fe6ef
3
+ metadata.gz: 55c9347ea971eed49f0ec9cf1e3734484a732b62fbdda2ee6bd294d17e561de5
4
+ data.tar.gz: 1cbaa083113de33ac60ac3a5bbac7efddc81742a550b7d3dfbd8b09bd200e591
5
5
  SHA512:
6
- metadata.gz: 72049ca8a11284d8e82e559c9481b5345b76bfbe5a8918fb226e19a1bbc24e99bac93d37170004e51b5c2477812ae54f1c83ac65a7babfef6b13f3370e64daa9
7
- data.tar.gz: 411d59f42dc93540c9a33c7f1b99ee7b7c9ebef40c9841a452a58a857160fb1777521289b2e93cfa8e9b1d9c5465eb50c0e48cc98054ee0faf524e4a64c983d4
6
+ metadata.gz: ebfbfc9153ec3e5778831a8ac9dabc5fcd1c95be9172eb56a3e4b98a1ebe232c5b9796b04d778e2f574b4eaddc41f3b0c98e1dd95348d17cf574401fc0a408db
7
+ data.tar.gz: 9d0b5bec0305a944d99111d8dcaa49ba1355101f1c7a9cddca66a606ed7bbabfb3132b4d338434a272e05ffcf547f4aaf04af8aeeade30ca1803599522f994ae
checksums.yaml.gz.sig CHANGED
Binary file
@@ -4,11 +4,11 @@
4
4
  # Copyright, 2016, by Matthew Kerwin.
5
5
  # Copyright, 2017-2024, by Samuel Williams.
6
6
 
7
- require 'strscan'
7
+ require "strscan"
8
8
 
9
- require_relative 'parse_error'
10
- require_relative 'quoted_string'
11
- require_relative 'sort'
9
+ require_relative "parse_error"
10
+ require_relative "quoted_string"
11
+ require_relative "sort"
12
12
 
13
13
  module HTTP
14
14
  module Accept
@@ -34,7 +34,7 @@ module HTTP
34
34
  break unless scanner.scan(/\s*,\s*/)
35
35
  end
36
36
 
37
- raise ParseError.new('Could not parse entire string!') unless scanner.eos?
37
+ raise ParseError.new("Could not parse entire string!") unless scanner.eos?
38
38
  end
39
39
  end
40
40
 
@@ -46,8 +46,8 @@ module HTTP
46
46
  return Sort.by_quality_factor(charsets)
47
47
  end
48
48
 
49
- HTTP_ACCEPT_CHARSET = 'HTTP_ACCEPT_CHARSET'.freeze
50
- WILDCARD_CHARSET = Charset.new('*', nil).freeze
49
+ HTTP_ACCEPT_CHARSET = "HTTP_ACCEPT_CHARSET".freeze
50
+ WILDCARD_CHARSET = Charset.new("*", nil).freeze
51
51
 
52
52
  # Parse the list of browser preferred charsets and return ordered by priority.
53
53
  def self.browser_preferred_charsets(env)
@@ -58,7 +58,7 @@ module HTTP
58
58
  # Accept-Charset = 1#( ( charset / "*" ) [ weight ] )
59
59
  #
60
60
  # Because of the `1#` rule, an empty header value is not considered valid.
61
- raise ParseError.new('Could not parse entire string!')
61
+ raise ParseError.new("Could not parse entire string!")
62
62
  else
63
63
  return HTTP::Accept::Charsets.parse(accept_charsets)
64
64
  end
@@ -3,8 +3,8 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2016-2024, by Samuel Williams.
5
5
 
6
- require_relative 'media_types'
7
- require_relative 'quoted_string'
6
+ require_relative "media_types"
7
+ require_relative "quoted_string"
8
8
 
9
9
  module HTTP
10
10
  module Accept
@@ -12,7 +12,7 @@ module HTTP
12
12
  class ContentType < MediaTypes::MediaRange
13
13
  def initialize(type, subtype, parameters = {})
14
14
  # We do some basic validation here:
15
- raise ArgumentError.new("#{self.class} can not have wildcards: #{type}", "#{subtype}") if type.include?('*') || subtype.include?('*')
15
+ raise ArgumentError.new("#{self.class} can not have wildcards: #{type}", "#{subtype}") if type.include?("*") || subtype.include?("*")
16
16
 
17
17
  super
18
18
  end
@@ -4,11 +4,11 @@
4
4
  # Copyright, 2016, by Matthew Kerwin.
5
5
  # Copyright, 2017-2024, by Samuel Williams.
6
6
 
7
- require 'strscan'
7
+ require "strscan"
8
8
 
9
- require_relative 'parse_error'
10
- require_relative 'quoted_string'
11
- require_relative 'sort'
9
+ require_relative "parse_error"
10
+ require_relative "quoted_string"
11
+ require_relative "sort"
12
12
 
13
13
  module HTTP
14
14
  module Accept
@@ -36,7 +36,7 @@ module HTTP
36
36
  break unless scanner.scan(/\s*,\s*/)
37
37
  end
38
38
 
39
- raise ParseError.new('Could not parse entire string!') unless scanner.eos?
39
+ raise ParseError.new("Could not parse entire string!") unless scanner.eos?
40
40
  end
41
41
  end
42
42
 
@@ -48,9 +48,9 @@ module HTTP
48
48
  return Sort.by_quality_factor(encodings)
49
49
  end
50
50
 
51
- HTTP_ACCEPT_ENCODING = 'HTTP_ACCEPT_ENCODING'.freeze
52
- WILDCARD_CONTENT_CODING = ContentCoding.new('*', nil).freeze
53
- IDENTITY_CONTENT_CODING = ContentCoding.new('identity', nil).freeze
51
+ HTTP_ACCEPT_ENCODING = "HTTP_ACCEPT_ENCODING".freeze
52
+ WILDCARD_CONTENT_CODING = ContentCoding.new("*", nil).freeze
53
+ IDENTITY_CONTENT_CODING = ContentCoding.new("identity", nil).freeze
54
54
 
55
55
  # Parse the list of browser preferred content codings and return ordered by priority. If no
56
56
  # `Accept-Encoding:` header is specified, the behaviour is the same as if
@@ -4,10 +4,10 @@
4
4
  # Copyright, 2016-2024, by Samuel Williams.
5
5
  # Copyright, 2021, by Khaled Hassan Hussein.
6
6
 
7
- require 'strscan'
7
+ require "strscan"
8
8
 
9
- require_relative 'parse_error'
10
- require_relative 'sort'
9
+ require_relative "parse_error"
10
+ require_relative "sort"
11
11
 
12
12
  module HTTP
13
13
  module Accept
@@ -24,10 +24,10 @@ module HTTP
24
24
  # Provides an efficient data-structure for matching the Accept-Languages header to set of available locales according to https://tools.ietf.org/html/rfc7231#section-5.3.5 and https://tools.ietf.org/html/rfc4647#section-2.3
25
25
  class Locales
26
26
  def self.expand(locale, into)
27
- parts = locale.split('-')
27
+ parts = locale.split("-")
28
28
 
29
29
  while parts.size > 0
30
- key = parts.join('-')
30
+ key = parts.join("-")
31
31
 
32
32
  into[key] ||= locale
33
33
 
@@ -27,8 +27,8 @@ module HTTP
27
27
  def for(media_types)
28
28
  media_types.each do |media_range|
29
29
  mime_type = case media_range
30
- when String then media_range
31
- else media_range.mime_type
30
+ when String then media_range
31
+ else media_range.mime_type
32
32
  end
33
33
 
34
34
  if object = @media_types[mime_type]
@@ -49,15 +49,15 @@ module HTTP
49
49
 
50
50
  # Add a converter to the collection. A converter can be anything that responds to #content_type. Objects will be considered in the order they are added, subsequent objects cannot override previously defined media types. `object` must respond to #split('/', 2) which should give the type and subtype.
51
51
  def << object
52
- type, subtype = object.split('/', 2)
52
+ type, subtype = object.split("/", 2)
53
53
 
54
54
  # We set the default if not specified already:
55
55
  @media_types[WILDCARD] = object if @media_types.empty?
56
56
 
57
- if type != '*'
57
+ if type != "*"
58
58
  @media_types["#{type}/*"] ||= object
59
59
 
60
- if subtype != '*'
60
+ if subtype != "*"
61
61
  @media_types["#{type}/#{subtype}"] ||= object
62
62
  end
63
63
  end
@@ -3,13 +3,13 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2016-2024, by Samuel Williams.
5
5
 
6
- require 'strscan'
6
+ require "strscan"
7
7
 
8
- require_relative 'parse_error'
9
- require_relative 'quoted_string'
10
- require_relative 'sort'
8
+ require_relative "parse_error"
9
+ require_relative "quoted_string"
10
+ require_relative "sort"
11
11
 
12
- require_relative 'media_types/map'
12
+ require_relative "media_types/map"
13
13
 
14
14
  module HTTP
15
15
  module Accept
@@ -21,12 +21,12 @@ module HTTP
21
21
 
22
22
  # A single entry in the Accept: header, which includes a mime type and associated parameters.
23
23
  MediaRange = Struct.new(:type, :subtype, :parameters) do
24
- def initialize(type, subtype = '*', parameters = {})
24
+ def initialize(type, subtype = "*", parameters = {})
25
25
  super(type, subtype, parameters)
26
26
  end
27
27
 
28
28
  def parameters_string
29
- return '' if parameters == nil or parameters.empty?
29
+ return "" if parameters == nil or parameters.empty?
30
30
 
31
31
  parameters.collect do |key, value|
32
32
  "; #{key.to_s}=#{QuotedString.quote(value.to_s)}"
@@ -52,7 +52,7 @@ module HTTP
52
52
  alias to_str to_s
53
53
 
54
54
  def quality_factor
55
- parameters.fetch('q', 1.0).to_f
55
+ parameters.fetch("q", 1.0).to_f
56
56
  end
57
57
 
58
58
  def split(*args)
@@ -103,7 +103,7 @@ module HTTP
103
103
  return Sort.by_quality_factor(media_types)
104
104
  end
105
105
 
106
- HTTP_ACCEPT = 'HTTP_ACCEPT'.freeze
106
+ HTTP_ACCEPT = "HTTP_ACCEPT".freeze
107
107
  WILDCARD_MEDIA_RANGE = MediaRange.new("*", "*", {}).freeze
108
108
 
109
109
  # Parse the list of browser preferred content types and return ordered by priority. If no `Accept:` header is specified, the behaviour is the same as if `Accept: */*` was provided (according to RFC).
@@ -7,7 +7,7 @@ module HTTP
7
7
  module Accept
8
8
  # According to https://tools.ietf.org/html/rfc7231#appendix-C
9
9
  TOKEN = /[!#$%&'*+\-.^_`|~0-9A-Z]+/i
10
- QUOTED_STRING = /"(?:.(?!(?<!\\)"))*.?"/
10
+ QUOTED_STRING = /"(?:[^"\\\r\n]|\\.)*"/
11
11
 
12
12
  module QuotedString
13
13
  # Unquote a "quoted-string" value according to https://tools.ietf.org/html/rfc7230#section-3.2.6
@@ -19,7 +19,7 @@ module HTTP
19
19
 
20
20
  if normalize_whitespace
21
21
  # LWS = [CRLF] 1*( SP | HT )
22
- value.gsub!(/[\r\n]+\s+/, ' ')
22
+ value.gsub!(/[\r\n]+\s+/, " ")
23
23
  end
24
24
 
25
25
  return value
@@ -5,6 +5,6 @@
5
5
 
6
6
  module HTTP
7
7
  module Accept
8
- VERSION = "2.2.1"
8
+ VERSION = "2.2.2"
9
9
  end
10
10
  end
data/lib/http/accept.rb CHANGED
@@ -5,17 +5,17 @@
5
5
  # Copyright, 2016, by Matthew Kerwin.
6
6
  # Copyright, 2017, by Andy Brody.
7
7
 
8
- require_relative 'accept/version'
8
+ require_relative "accept/version"
9
9
 
10
10
  # Accept: header
11
- require_relative 'accept/media_types'
12
- require_relative 'accept/content_type'
11
+ require_relative "accept/media_types"
12
+ require_relative "accept/content_type"
13
13
 
14
14
  # Accept-Encoding: header
15
- require_relative 'accept/encodings'
15
+ require_relative "accept/encodings"
16
16
 
17
17
  # Accept-Language: header
18
- require_relative 'accept/languages'
18
+ require_relative "accept/languages"
19
19
 
20
20
  module HTTP
21
21
  module Accept
data/license.md CHANGED
@@ -8,6 +8,7 @@ Copyright, 2019, by Robert Pritzkow.
8
8
  Copyright, 2020, by Olle Jonsson.
9
9
  Copyright, 2021, by Khaled Hassan Hussein.
10
10
  Copyright, 2022, by Ian Oxley.
11
+ Copyright, 2025, by Alexis Bernard.
11
12
 
12
13
  Permission is hereby granted, free of charge, to any person obtaining a copy
13
14
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -17,7 +17,7 @@ I am concerned about correctness, security and performance. As such, I implement
17
17
  Add this line to your application's Gemfile:
18
18
 
19
19
  ``` ruby
20
- gem 'http-accept'
20
+ gem "http-accept"
21
21
  ```
22
22
 
23
23
  And then execute:
@@ -31,12 +31,12 @@ Or install it yourself as:
31
31
  You can then require it in your code like so:
32
32
 
33
33
  ``` ruby
34
- require 'http/accept'
34
+ require "http/accept"
35
35
  ```
36
36
 
37
37
  ## Usage
38
38
 
39
- Here are some examples of how to parse various headers.
39
+ Please see the [project documentation](https://github.com/ioquatix/http-accept) for more details.
40
40
 
41
41
  ### Parsing Accept: headers
42
42
 
@@ -46,31 +46,31 @@ You can parse the incoming `Accept:` header:
46
46
  media_types = HTTP::Accept::MediaTypes.parse("text/html;q=0.5, application/json; version=1")
47
47
 
48
48
  expect(media_types[0].mime_type).to be == "application/json"
49
- expect(media_types[0].parameters).to be == {'version' => '1'}
49
+ expect(media_types[0].parameters).to be == {"version" => "1"}
50
50
  expect(media_types[1].mime_type).to be == "text/html"
51
- expect(media_types[1].parameters).to be == {'q' => '0.5'}
51
+ expect(media_types[1].parameters).to be == {"q" => "0.5"}
52
52
  ```
53
53
 
54
54
  Normally, you'd want to match the media types against some set of available mime types:
55
55
 
56
56
  ``` ruby
57
57
  module ToJSON
58
- def content_type
59
- HTTP::Accept::ContentType.new("application", "json", charset: 'utf-8')
60
- end
61
-
62
- # Used for inserting into map.
63
- def split(*args)
64
- content_type.split(*args)
65
- end
66
-
67
- def convert(object, options)
68
- object.to_json
69
- end
58
+ def content_type
59
+ HTTP::Accept::ContentType.new("application", "json", charset: "utf-8")
60
+ end
61
+
62
+ # Used for inserting into map.
63
+ def split(*args)
64
+ content_type.split(*args)
65
+ end
66
+
67
+ def convert(object, options)
68
+ object.to_json
69
+ end
70
70
  end
71
71
 
72
72
  module ToXML
73
- # Are you kidding?
73
+ # Are you kidding?
74
74
  end
75
75
 
76
76
  map = HTTP::Accept::MediaTypes::Map.new
@@ -79,7 +79,7 @@ map << ToXML
79
79
 
80
80
  object, media_range = map.for(media_types)
81
81
  content = object.convert(model, media_range.parameters)
82
- response = [200, {'Content-Type' => object.content_type}, [content]]
82
+ response = [200, {"Content-Type" => object.content_type}, [content]]
83
83
  ```
84
84
 
85
85
  ### Parsing Accept-Language: headers
@@ -107,20 +107,44 @@ The `desired_localizations` in the example above is a subset of `available_local
107
107
 
108
108
  `HTTP::Accept::Languages::Locales` provides an efficient data-structure for matching the Accept-Languages header to set of available localizations according to <https://tools.ietf.org/html/rfc7231#section-5.3.5> and <https://tools.ietf.org/html/rfc4647#section-2.3>
109
109
 
110
+ ## Releases
111
+
112
+ Please see the [project releases](https://github.com/ioquatix/http-acceptreleases/index) for all releases.
113
+
114
+ ### v2.2.2
115
+
116
+ - Fix handling of quoted strings.
117
+
110
118
  ## Contributing
111
119
 
112
120
  We welcome contributions to this project.
113
121
 
114
- 1. Fork it.
122
+ 1. Fork the repository.
115
123
  2. Create your feature branch (`git checkout -b my-new-feature`).
116
- 3. Commit your changes (`git commit -am 'Add some feature'`).
124
+ 3. Commit your changes (`git commit -am 'Add some feature.'`).
117
125
  4. Push to the branch (`git push origin my-new-feature`).
118
- 5. Create new Pull Request.
126
+ 5. Create a new pull request.
127
+
128
+ ### Running Tests
129
+
130
+ To run the test suite:
131
+
132
+ ``` bash
133
+ $ bundle exec sus
134
+ ```
135
+
136
+ ### Making Releases
137
+
138
+ To make a new release:
139
+
140
+ ``` bash
141
+ $ bundle exec bake gem:release:patch # or minor or major
142
+ ```
119
143
 
120
144
  ### Developer Certificate of Origin
121
145
 
122
- This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
146
+ In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
123
147
 
124
- ### Contributor Covenant
148
+ ### Community Guidelines
125
149
 
126
- This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
150
+ This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
data/releases.md ADDED
@@ -0,0 +1,5 @@
1
+ # Releases
2
+
3
+ ## v2.2.2
4
+
5
+ - Fix handling of quoted strings.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-accept
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Alexis Bernard
8
9
  - Matthew Kerwin
9
10
  - Alif Rachmawadi
10
11
  - Andy Brody
@@ -12,7 +13,6 @@ authors:
12
13
  - Khaled Hassan Hussein
13
14
  - Olle Jonsson
14
15
  - Robert Pritzkow
15
- autorequire:
16
16
  bindir: bin
17
17
  cert_chain:
18
18
  - |
@@ -44,15 +44,12 @@ cert_chain:
44
44
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
45
45
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
46
46
  -----END CERTIFICATE-----
47
- date: 2024-02-05 00:00:00.000000000 Z
47
+ date: 1980-01-02 00:00:00.000000000 Z
48
48
  dependencies: []
49
- description:
50
- email:
51
49
  executables: []
52
50
  extensions: []
53
51
  extra_rdoc_files: []
54
52
  files:
55
- - lib/.DS_Store
56
53
  - lib/http/accept.rb
57
54
  - lib/http/accept/charsets.rb
58
55
  - lib/http/accept/content_type.rb
@@ -66,12 +63,15 @@ files:
66
63
  - lib/http/accept/version.rb
67
64
  - license.md
68
65
  - readme.md
66
+ - releases.md
69
67
  homepage: https://github.com/ioquatix/http-accept
70
68
  licenses:
71
69
  - MIT
72
70
  metadata:
71
+ bug_tracker_uri: https://github.com/ioquatix/http-accept/issues
72
+ changelog_uri: https://github.com/ioquatix/http-accept/blob/main/releases.md
73
73
  funding_uri: https://github.com/sponsors/ioquatix/
74
- post_install_message:
74
+ source_code_uri: https://github.com/ioquatix/http-accept.git
75
75
  rdoc_options: []
76
76
  require_paths:
77
77
  - lib
@@ -79,15 +79,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '3.3'
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.5.3
90
- signing_key:
89
+ rubygems_version: 4.0.10
91
90
  specification_version: 4
92
91
  summary: Parse Accept and Accept-Language HTTP headers.
93
92
  test_files: []
metadata.gz.sig CHANGED
Binary file
data/lib/.DS_Store DELETED
Binary file