From 3fc4be57043ac678cf23bc00ad84a7d90c7df9d2 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Mon, 14 Sep 2026 11:18:49 -0700 Subject: [PATCH] fix: align runtime and test compatibility --- gems/smithy-client/lib/smithy-client/util.rb | 12 ++++++++++- .../spec/smithy-client/util_spec.rb | 21 +++++++++++++++++++ gems/smithy-client/spec/spec_helper.rb | 12 +++++------ .../sig/smithy-schema/shapes.rbs | 4 ++-- gems/smithy-xml/spec/spec_helper.rb | 12 +++++------ 5 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 gems/smithy-client/spec/smithy-client/util_spec.rb diff --git a/gems/smithy-client/lib/smithy-client/util.rb b/gems/smithy-client/lib/smithy-client/util.rb index b8968b148..b20a837f1 100644 --- a/gems/smithy-client/lib/smithy-client/util.rb +++ b/gems/smithy-client/lib/smithy-client/util.rb @@ -1,15 +1,25 @@ # frozen_string_literal: true +require 'cgi/escape' +require 'cgi/util' if RUBY_VERSION < '3.5' + module Smithy module Client # @api private module Util def self.str_to_bool(str) - case str + case str.to_s when 'true' then true when 'false' then false end end + + def self.escape(value) + encoded = CGI.escape(value.encode('UTF-8')) + encoded = encoded.gsub('+', '%20') if encoded.include?('+') + encoded = encoded.gsub('%7E', '~') if encoded.include?('%7E') + encoded + end end end end diff --git a/gems/smithy-client/spec/smithy-client/util_spec.rb b/gems/smithy-client/spec/smithy-client/util_spec.rb new file mode 100644 index 000000000..c565c2060 --- /dev/null +++ b/gems/smithy-client/spec/smithy-client/util_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative '../spec_helper' + +module Smithy + module Client + describe Util do + describe '.escape' do + it 'uses RFC 3986 query escaping' do + expect(described_class.escape('a value~')).to eq('a%20value~') + end + end + + describe '.str_to_bool' do + it 'accepts values that stringify to a supported boolean' do + expect(described_class.str_to_bool(true)).to be(true) + end + end + end + end +end diff --git a/gems/smithy-client/spec/spec_helper.rb b/gems/smithy-client/spec/spec_helper.rb index bfb85192a..c7f7fa98d 100644 --- a/gems/smithy-client/spec/spec_helper.rb +++ b/gems/smithy-client/spec/spec_helper.rb @@ -4,12 +4,12 @@ require 'simplecov' SimpleCov.start do - add_filter '/spec/' - add_filter 'gems/smithy/' - add_filter 'gems/smithy-cbor/' - add_filter 'gems/smithy-json/' - add_filter 'gems/smithy-schema/' - add_filter 'gems/smithy-xml/' + skip '/spec/' + skip 'gems/smithy/' + skip 'gems/smithy-cbor/' + skip 'gems/smithy-json/' + skip 'gems/smithy-schema/' + skip 'gems/smithy-xml/' end require 'smithy' diff --git a/gems/smithy-schema/sig/smithy-schema/shapes.rbs b/gems/smithy-schema/sig/smithy-schema/shapes.rbs index 86e209510..8b8cfd9fe 100644 --- a/gems/smithy-schema/sig/smithy-schema/shapes.rbs +++ b/gems/smithy-schema/sig/smithy-schema/shapes.rbs @@ -90,7 +90,7 @@ module Smithy class StructureShape < Shape attr_accessor members: Hash[Symbol, MemberShape] - attr_accessor type: Class | Struct[untyped] + attr_accessor type: (Class | Struct[untyped])? def add_member: (Symbol, MemberShape) -> MemberShape def member?: (Symbol?) -> bool def member: (Symbol) -> MemberShape? @@ -103,7 +103,7 @@ module Smithy attr_accessor members: Hash[Symbol, MemberShape] attr_accessor member_types: Hash[Symbol, Class] attr_accessor members_by_type: Hash[Class, [Symbol, MemberShape]] - attr_accessor type: Class | Struct[untyped] + attr_accessor type: (Class | Struct[untyped])? def add_member: (Symbol, Class, MemberShape) -> MemberShape def member?: (Symbol?) -> bool def member: (Symbol) -> MemberShape? diff --git a/gems/smithy-xml/spec/spec_helper.rb b/gems/smithy-xml/spec/spec_helper.rb index 6df750a27..2676b3c55 100644 --- a/gems/smithy-xml/spec/spec_helper.rb +++ b/gems/smithy-xml/spec/spec_helper.rb @@ -2,12 +2,12 @@ require 'simplecov' SimpleCov.start do - add_filter '/spec/' - add_filter 'gems/smithy/' - add_filter 'gems/smithy-cbor/' - add_filter 'gems/smithy-client/' - add_filter 'gems/smithy-json/' - add_filter 'gems/smithy-schema/' + skip '/spec/' + skip 'gems/smithy/' + skip 'gems/smithy-cbor/' + skip 'gems/smithy-client/' + skip 'gems/smithy-json/' + skip 'gems/smithy-schema/' end require 'smithy-xml'