Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion gems/smithy-client/lib/smithy-client/util.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions gems/smithy-client/spec/smithy-client/util_spec.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions gems/smithy-client/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions gems/smithy-schema/sig/smithy-schema/shapes.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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?
Expand Down
12 changes: 6 additions & 6 deletions gems/smithy-xml/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I just noticed these, but what does changing add_filter to skip do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s no behavior change. skip is the replacement for the deprecated add_filter API so we won't get annoying SimpleCov warning anymore! :D

skip 'gems/smithy/'
skip 'gems/smithy-cbor/'
skip 'gems/smithy-client/'
skip 'gems/smithy-json/'
skip 'gems/smithy-schema/'
end

require 'smithy-xml'
Expand Down
Loading