From 32d8b436c49291078d45a5751651085cfc18d75a Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Sat, 28 Mar 2020 09:58:01 +0100 Subject: [PATCH] better quote special pattern characters --- lib/resty/openidc.lua | 4 ++-- tests/spec/pkce_spec.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/resty/openidc.lua b/lib/resty/openidc.lua index f927a06..ddfa804 100644 --- a/lib/resty/openidc.lua +++ b/lib/resty/openidc.lua @@ -291,14 +291,14 @@ local function openidc_base64_url_decode(input) local padlen = 4 - reminder input = input .. string.rep('=', padlen) end - input = input:gsub('-', '+'):gsub('_', '/') + input = input:gsub('%-', '+'):gsub('_', '/') return unb64(input) end -- perform base64url encoding local function openidc_base64_url_encode(input) local output = b64(input, true) - return output:gsub('+', '-'):gsub('/', '_') + return output:gsub('%+', '-'):gsub('/', '_') end local function openidc_combine_uri(uri, params) diff --git a/tests/spec/pkce_spec.lua b/tests/spec/pkce_spec.lua index 1b91ea7..be93a0c 100644 --- a/tests/spec/pkce_spec.lua +++ b/tests/spec/pkce_spec.lua @@ -53,7 +53,7 @@ describe('when pkce is disabled and the token endpoint is invoked', function() end) end) -describe('when pkce is disabled and the token endpoint is invoked', function() +describe('when pkce is enabled and the token endpoint is invoked', function() test_support.start_server({oidc_opts = { use_pkce = true } }) teardown(test_support.stop_server) @@ -81,7 +81,7 @@ describe('when pkce is disabled and the token endpoint is invoked', function() if rem > 0 then s = s .. string.rep('=', 4 - rem) end - return s:gsub('-', '+'):gsub('_', '/') + return s:gsub('%-', '+'):gsub('_', '/') end local challenge = as_base64(code_challenge) local hashed_verifier = (require 'mime').b64((require 'sha2').bytes(code_verifier))