Skip to content

Commit

Permalink
Playground block: Document the lenient fallback in base64 decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed May 13, 2024
1 parent be317ed commit b189b9f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/wordpress-playground-block/src/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export function base64EncodeBlockAttributes(
base64Props[key] = blockAttributes[key];
continue;
}
base64Props[key] = stringToBase64(
JSON.stringify(blockAttributes[key])
);
base64Props[key] = stringToBase64(JSON.stringify(blockAttributes[key]));
}
// The "files" attribute is of type array
if ('files' in base64Props) {
Expand Down Expand Up @@ -71,6 +69,9 @@ export function base64DecodeBlockAttributes(
attributes[key] = JSON.parse(base64ToString(valueToDecode));
} catch (error) {
// Ignore errors and keep the base64 encoded string.
// Note this will also preserve any non-base64 encoded values.
// This is intentional as it seems to make more sense than
// throwing an error and breaking the block.
attributes[key] = base64Attributes[key];
}
}
Expand Down

0 comments on commit b189b9f

Please sign in to comment.