Skip to content
Browse files

Fix the reserved characters regex to be non-variant by $KCODE

  • Loading branch information...
1 parent dd3bcd1 commit 470c08ec3a9b55e85a6f5bbc730d387f3bf7afa2 Matt Sanford committed with mojodna
Showing with 21 additions and 12 deletions.
  1. +1 −0 History.txt
  2. +1 −1 lib/oauth/oauth.rb
  3. +19 −11 test/test_signature.rb
View
1 History.txt
@@ -2,6 +2,7 @@
* Corrected OAuth XMPP namespace (Seth)
* Improved error handling for invalid Authorization headers (Matt Sanford)
+* Fixed signatures for non-ASCII under $KCODE other than 'u' (Matt Sanford)
== 0.3.2 2009-03-23
View
2 lib/oauth/oauth.rb
@@ -3,5 +3,5 @@ module OAuth
PARAMETERS = %w(oauth_consumer_key oauth_token oauth_signature_method oauth_timestamp oauth_nonce oauth_version oauth_signature)
# reserved character regexp, per section 5.1
- RESERVED_CHARACTERS = /[^\w\d\-\.\_\~]/
+ RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
end
View
30 test/test_signature.rb
@@ -1,11 +1,19 @@
-require File.dirname(__FILE__) + '/test_helper.rb'
-
-class TestOauth < Test::Unit::TestCase
-
- def setup
- end
-
- def test_truth
- assert true
- end
-end
+require File.dirname(__FILE__) + '/test_helper.rb'
+
+class TestOauth < Test::Unit::TestCase
+
+ def test_parameter_escaping_kcode_invariant
+ old = $KCODE
+ begin
+ %w(n N e E s S u U).each do |kcode|
+ $KCODE = kcode
+ assert_equal '%E3%81%82', OAuth::Helper.escape(''),
+ "Failed to correctly escape Japanese under $KCODE = #{kcode}"
+ assert_equal '%C3%A9', OAuth::Helper.escape('é'),
+ "Failed to correctly escape e+acute under $KCODE = #{kcode}"
+ end
+ ensure
+ $KCODE = old
+ end
+ end
+end

0 comments on commit 470c08e

Please sign in to comment.
Something went wrong with that request. Please try again.