@@ -223,20 +223,24 @@ RETURNS bytea AS $$
|
|||||||
DECLARE
|
DECLARE
|
||||||
padded_text text;
|
padded_text text;
|
||||||
mod_length integer;
|
mod_length integer;
|
||||||
|
normalized_text text;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
-- Replace URL-safe characters with standard base64 characters
|
||||||
|
normalized_text := translate(input_text, '-_', '+/');
|
||||||
|
|
||||||
-- Calculate how many padding characters we need to add
|
-- Calculate how many padding characters we need to add
|
||||||
mod_length := length(input_text) % 4;
|
mod_length := length(normalized_text) % 4;
|
||||||
|
|
||||||
-- Add the required padding
|
-- Add the required padding
|
||||||
IF mod_length = 0 THEN
|
IF mod_length = 0 THEN
|
||||||
padded_text := input_text;
|
padded_text := normalized_text;
|
||||||
ELSIF mod_length = 1 THEN
|
ELSIF mod_length = 1 THEN
|
||||||
-- Invalid base64 - length mod 4 can't be 1
|
-- Invalid base64 - length mod 4 can't be 1
|
||||||
RAISE EXCEPTION 'Invalid base64 length';
|
RAISE EXCEPTION 'Invalid base64 length';
|
||||||
ELSIF mod_length = 2 THEN
|
ELSIF mod_length = 2 THEN
|
||||||
padded_text := input_text || '==';
|
padded_text := normalized_text || '==';
|
||||||
ELSIF mod_length = 3 THEN
|
ELSIF mod_length = 3 THEN
|
||||||
padded_text := input_text || '=';
|
padded_text := normalized_text || '=';
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Decode the padded base64
|
-- Decode the padded base64
|
||||||
|
|||||||
Reference in New Issue
Block a user