cloud_events 0.8.1 → 0.8.3

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: 5e5bb2b1e01aef9e34dca014ee2be62da7b2abaea1337c3db3f51c4dc9b6b790
4
- data.tar.gz: 1c439ec71a81da471e67ebcc9de437b34be067c18a293790f0f9a098b3f0862b
3
+ metadata.gz: 2a711fe27eaab25a87e694f6436b2c34506b3a776457a77583c3f0f4bb0744ed
4
+ data.tar.gz: 01e81b176023ca2369999d2257c3157d4cef267ff0951e09a2df09f2848af0f5
5
5
  SHA512:
6
- metadata.gz: 69a9b60f9d6d2a10ca5b22bbe171eba142d1864e90eed97bc8db8318d54070a64f916093ba92674eb08076e113f421584249bf114a6293f61c864ec48576e97a
7
- data.tar.gz: ff8ac3a95310bbd915ee96efdb767575b4f094ae01a4b2e136a2e52e407b2c1c62d31e8dc4216c12ccb1267dec279a596eaeba7e16927d7a0768758e356817e7
6
+ metadata.gz: 96e2b1892b58bd5944d506ffff3e30a899fcb1bc03c31018637788cc8772def582e258b31f35786ebad8d054f22bfcbf2fdbe98e573ff098c2f89e2d8da4e1a0
7
+ data.tar.gz: e058c5c54f57224d02d42c9f52d7a320ef319b72573aa0d162f2362e06a0294bdd1f81f7705d55f47b40d8eadf418de85efb09c68c797978fcf0e5b49c91c1f4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.8.3 / 2026-01-15
4
+
5
+ * FIXED: Fixed default charset behavior for various non-text/plain content types
6
+
7
+ ### v0.8.2 / 2025-11-30
8
+
9
+ * DOCS: Fixed a few typos in documentation and error messages
10
+
3
11
  ### v0.8.1 / 2025-11-10
4
12
 
5
13
  * DOCS: Some minor updates and corrections to the README and examples
@@ -22,17 +22,15 @@ module CloudEvents
22
22
  #
23
23
  # @param string [String] Content-Type header value in RFC 2045 format
24
24
  # @param default_charset [String] Optional. The charset to use if none is
25
- # specified. Defaults to `us-ascii`.
25
+ # specified. Defaults to `utf-8` for all types other than `text/plain`
26
+ # for which it defaults to `us-ascii`.
26
27
  #
27
28
  def initialize(string, default_charset: nil)
28
29
  @string = string.to_s
29
- @media_type = "text"
30
- @subtype_base = @subtype = "plain"
31
- @subtype_format = nil
30
+ @media_type = @subtype = @subtype_base = @subtype_format = @charset = nil
32
31
  @params = []
33
- @charset = default_charset || "us-ascii"
34
32
  @error_message = nil
35
- parse(consume_comments(@string.strip))
33
+ parse(consume_comments(@string.strip), default_charset)
36
34
  @canonical_string = "#{@media_type}/#{@subtype}" +
37
35
  @params.map { |k, v| "; #{k}=#{maybe_quote(v)}" }.join
38
36
  full_freeze
@@ -86,8 +84,10 @@ module CloudEvents
86
84
  attr_reader :params
87
85
 
88
86
  ##
89
- # The charset, defaulting to "us-ascii" if none is explicitly set.
90
- # @return [String]
87
+ # Returns the charset, which may be an appropriate default (e.g. `us-ascii`
88
+ # for `text/plain`, or `utf-8` for `application/json`), or may be nil for
89
+ # non-text cases.
90
+ # @return [String,nil]
91
91
  #
92
92
  attr_reader :charset
93
93
 
@@ -124,14 +124,14 @@ module CloudEvents
124
124
 
125
125
  private
126
126
 
127
- def parse(str)
127
+ def parse(str, default_charset)
128
128
  @media_type, str = consume_token(str, downcase: true, error_message: "Failed to parse media type")
129
129
  str = consume_special(str, "/")
130
130
  @subtype, str = consume_token(str, downcase: true, error_message: "Failed to parse subtype")
131
131
  @subtype_base, @subtype_format = @subtype.split("+", 2)
132
132
  until str.empty?
133
133
  str = consume_special(str, ";")
134
- name, str = consume_token(str, downcase: true, error_message: "Faled to parse attribute name")
134
+ name, str = consume_token(str, downcase: true, error_message: "Failed to parse attribute name")
135
135
  str = consume_special(str, "=", error_message: "Failed to find value for attribute #{name}")
136
136
  val, str = consume_token_or_quoted(str, error_message: "Failed to parse value for attribute #{name}")
137
137
  @params << [name, val]
@@ -139,6 +139,13 @@ module CloudEvents
139
139
  end
140
140
  rescue ParseError => e
141
141
  @error_message = e.message
142
+ ensure
143
+ unless @subtype
144
+ @media_type = "text"
145
+ @subtype_base = @subtype = "plain"
146
+ @subtype_format = nil
147
+ end
148
+ @charset ||= default_charset || choose_default_charset
142
149
  end
143
150
 
144
151
  def consume_token(str, downcase: false, error_message: nil)
@@ -210,6 +217,14 @@ module CloudEvents
210
217
  "\"#{str}\""
211
218
  end
212
219
 
220
+ def choose_default_charset
221
+ if @media_type == "text" && @subtype == "plain"
222
+ "us-ascii"
223
+ elsif @media_type == "text" || @subtype_base == "json" || @subtype_format == "json"
224
+ "utf-8"
225
+ end
226
+ end
227
+
213
228
  def full_freeze
214
229
  instance_variables.each do |iv|
215
230
  instance_variable_get(iv).freeze
@@ -8,7 +8,7 @@ module CloudEvents
8
8
  # single event or a batch of events.
9
9
  #
10
10
  # The event data is retained in a form that can be reserialized (in a
11
- # structured cotent mode in the same format) but cannot otherwise be
11
+ # structured content mode in the same format) but cannot otherwise be
12
12
  # inspected.
13
13
  #
14
14
  # This object is immutable, and Ractor-shareable on Ruby 3.
@@ -30,7 +30,7 @@ module CloudEvents
30
30
  #
31
31
  # Both the keyword arguments recognized and the returned hash members may
32
32
  # vary from formatter to formatter; similarly, the keyword arguments provided
33
- # and the resturned hash members recognized may also vary for different
33
+ # and the returned hash members recognized may also vary for different
34
34
  # callers. This interface will define a set of common argument and result key
35
35
  # names, but both callers and formatters must gracefully handle the case of
36
36
  # missing or extra information. For example, if a formatter expects a certain
@@ -37,7 +37,7 @@ module CloudEvents
37
37
  end
38
38
 
39
39
  ##
40
- # Trivially an event data object using text format.
40
+ # Trivially encode an event data object using text format.
41
41
  # See {CloudEvents::Format#encode_data} for a general description.
42
42
  #
43
43
  # Expects `:data` and `:content_type` arguments, and will decline the
@@ -5,5 +5,5 @@ module CloudEvents
5
5
  # Version of the Ruby CloudEvents SDK
6
6
  # @return [String]
7
7
  #
8
- VERSION = "0.8.1"
8
+ VERSION = "0.8.3"
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
@@ -42,10 +42,10 @@ homepage: https://github.com/cloudevents/sdk-ruby
42
42
  licenses:
43
43
  - Apache-2.0
44
44
  metadata:
45
- changelog_uri: https://cloudevents.github.io/sdk-ruby/v0.8.1/file.CHANGELOG.html
45
+ changelog_uri: https://cloudevents.github.io/sdk-ruby/v0.8.3/file.CHANGELOG.html
46
46
  source_code_uri: https://github.com/cloudevents/sdk-ruby
47
47
  bug_tracker_uri: https://github.com/cloudevents/sdk-ruby/issues
48
- documentation_uri: https://cloudevents.github.io/sdk-ruby/v0.8.1
48
+ documentation_uri: https://cloudevents.github.io/sdk-ruby/v0.8.3
49
49
  rdoc_options: []
50
50
  require_paths:
51
51
  - lib
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.6.9
63
+ rubygems_version: 4.0.3
64
64
  specification_version: 4
65
65
  summary: Ruby SDK for CloudEvents
66
66
  test_files: []