Skip to content

Commit

Permalink
encode_base64 last_key
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Sep 23, 2024
1 parent fe0cc9b commit 5fd5ade
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ local next = next
local assert = assert
--local tostring = tostring
--local tonumber = tonumber
--local encode_base64 = ngx.encode_base64
--local decode_base64 = ngx.decode_base64
local encode_base64 = ngx.encode_base64
local decode_base64 = ngx.decode_base64
local null = ngx.null
local unmarshall = marshaller.unmarshall
--local marshall = marshaller.marshall
Expand Down Expand Up @@ -144,7 +144,7 @@ local function page_for_prefix(self, prefix, size, offset, options, follow)
end

if err_or_more then
return ret, nil, last_key .. "\x00"
return ret, nil, encode_base64(last_key .. "\x00", true)
end

return ret
Expand All @@ -155,6 +155,22 @@ local function page(self, size, offset, options)
local schema = self.schema
local ws_id = workspace_id(schema, options)
local prefix = item_key_prefix(schema.name, ws_id)

if offset then
local token = decode_base64(offset)
if not token then
return nil, self.errors:invalid_offset(offset, "bad base64 encoding")
end

--local number = tonumber(token)
--if not number then
-- return nil, self.errors:invalid_offset(offset, "invalid offset")
--end

offset = token

end

return page_for_prefix(self, prefix, size, offset, options, false)
end

Expand Down

0 comments on commit 5fd5ade

Please sign in to comment.