diff --git a/components/utils/base-64.utils.test.ts b/components/utils/base-64.utils.test.ts index 293c4b0..6bb2d3b 100644 --- a/components/utils/base-64.utils.test.ts +++ b/components/utils/base-64.utils.test.ts @@ -36,6 +36,11 @@ describe("base-64.utils", () => { expect(fromBase64(wrapped)).toBe(message); }); + test("should decode base64 of multiline text", () => { + const multiline = "This is the first line\n\nthis is another one"; + expect(fromBase64(toBase64(multiline))).toBe(multiline); + }); + test("should throw an error for an invalid Base64 string", () => { expect(() => fromBase64("invalid_base64")).toThrow( "Invalid Base64 input" diff --git a/components/utils/base-64.utils.ts b/components/utils/base-64.utils.ts index 0fe990f..4f53468 100644 --- a/components/utils/base-64.utils.ts +++ b/components/utils/base-64.utils.ts @@ -46,8 +46,9 @@ export function fromBase64(value: string): string { /** * Checks if the given string consists entirely of printable ASCII characters. - * Printable ASCII characters are those in the range from space (0x20) to tilde (0x7E). + * Printable ASCII characters are those in the range from space (0x20) to tilde (0x7E), + * plus common whitespace characters (tab, carriage return, line feed). */ export function isPrintableASCII(str: string): boolean { - return /^[\x20-\x7E]*$/.test(str); + return /^[\x20-\x7E\t\r\n]*$/.test(str); }