]> git.openstreetmap.org Git - rails.git/commitdiff
Handle UTF-8 correctly in monkey patched OAuth::Helper.escape
authorTom Hughes <tom@compton.nu>
Mon, 26 Apr 2021 21:06:19 +0000 (22:06 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 26 Apr 2021 21:10:45 +0000 (22:10 +0100)
Fixes #3185

config/initializers/oauth.rb

index bad01dd3dc0fa097431b928e877480490283ee52..276fd350ced5c35d841b7bd100c5aeaf7fc25b8d 100644 (file)
@@ -1,4 +1,5 @@
 require "oauth/controllers/provider_controller"
+require "oauth/helper"
 require "oauth/rack/oauth_filter"
 
 Rails.configuration.middleware.use OAuth::Rack::OAuthFilter
@@ -7,8 +8,10 @@ module OAuth
   module Helper
     def escape(value)
       value.to_s.gsub(OAuth::RESERVED_CHARACTERS) do |c|
-        format("%%%02X", c.ord)
-      end
+        c.bytes.map do |b|
+          format("%%%02X", b)
+        end.join
+      end.force_encoding(Encoding::US_ASCII)
     end
   end