Skip to content

Commit

Permalink
Fix 0.1.5 which erroneously escaped query params
Browse files Browse the repository at this point in the history
This is probably a desirable change but breaks backwards compatibility so will have to wait for auth_version 2.
  • Loading branch information
mloughran committed Nov 19, 2012
1 parent de85b06 commit f0e20ac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def parameter_string
# Exclude signature from signature generation!
hash.delete("auth_signature")

hash.sort.map { |k, v| QueryEncoder.encode_param(k, v) }.join('&')
hash.sort.map do |k, v|
QueryEncoder.encode_param_without_escaping(k, v)
end.join('&')
end

def validate_version!
Expand Down
9 changes: 9 additions & 0 deletions lib/signature/query_encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ def encode_param(k, v)
end
end

# Like encode_param, but doesn't url escape keys or values
def encode_param_without_escaping(k, v)
if v.is_a?(Array)
v.map { |e| k + "[]=" + e }.join("&")
else
k + "=" + v
end
end

private

def escape(s)
Expand Down
8 changes: 8 additions & 0 deletions spec/signature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
@request.send(:string_to_sign).should == "POST\n/some/path\nthings[]=thing1&things[]=thing2"
end

# This may well change in auth version 2
it "should not escape keys or values in the query string" do
@request.query_hash = {
"key;" => "value@"
}
@request.send(:string_to_sign).should == "POST\n/some/path\nkey;=value@"
end

it "should use the path to generate signature" do
@request.path = '/some/other/path'
@request.sign(@token)[:auth_signature].should_not == @signature
Expand Down

0 comments on commit f0e20ac

Please sign in to comment.