-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1748 from gfx/urlsafe_decode64_for_forward_compat…
…ibility Use Base64.urlsafe_decode64 for forward compatibility
- Loading branch information
Showing
4 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'base64' | ||
|
||
require 'graphql/relay/page_info' | ||
require 'graphql/relay/edge' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'base64' | ||
|
||
# backport from ruby v2.5 to v2.2 that has no `padding` things | ||
# @api private | ||
module Base64Bp | ||
extend Base64 | ||
|
||
module_function | ||
|
||
def urlsafe_encode64(bin, padding:) | ||
str = strict_encode64(bin).tr("+/", "-_") | ||
str = str.delete("=") unless padding | ||
str | ||
end | ||
|
||
def urlsafe_decode64(str) | ||
str = str.tr("-_", "+/") | ||
if !str.end_with?("=") && str.length % 4 != 0 | ||
str = str.ljust((str.length + 3) & ~3, "=") | ||
end | ||
strict_decode64(str) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters