From c8d45b85e2bdadeb823a924774ee0292073ef2c4 Mon Sep 17 00:00:00 2001 From: Bryan Frimin Date: Wed, 23 Apr 2025 13:48:09 -0700 Subject: [PATCH] Fix base64 decode Signed-off-by: Bryan Frimin --- pkg/coredata/migrations/20250420T120000Z.sql | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/coredata/migrations/20250420T120000Z.sql b/pkg/coredata/migrations/20250420T120000Z.sql index 0ce13b00e..8c5b905d6 100644 --- a/pkg/coredata/migrations/20250420T120000Z.sql +++ b/pkg/coredata/migrations/20250420T120000Z.sql @@ -223,20 +223,24 @@ RETURNS bytea AS $$ DECLARE padded_text text; mod_length integer; + normalized_text text; BEGIN + -- Replace URL-safe characters with standard base64 characters + normalized_text := translate(input_text, '-_', '+/'); + -- 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 IF mod_length = 0 THEN - padded_text := input_text; + padded_text := normalized_text; ELSIF mod_length = 1 THEN -- Invalid base64 - length mod 4 can't be 1 RAISE EXCEPTION 'Invalid base64 length'; ELSIF mod_length = 2 THEN - padded_text := input_text || '=='; + padded_text := normalized_text || '=='; ELSIF mod_length = 3 THEN - padded_text := input_text || '='; + padded_text := normalized_text || '='; END IF; -- Decode the padded base64