1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

Handle null in utils

This commit is contained in:
Matt Gibson
2022-08-31 16:03:04 -04:00
parent ee6258bd3d
commit 1fb6207e53
2 changed files with 9 additions and 0 deletions

View File

@@ -70,4 +70,10 @@ describe("Utils Service", () => {
expect(Utils.newGuid()).toMatch(validGuid);
});
});
describe("fromByteStringToArray", () => {
it("should handle null", () => {
expect(Utils.fromByteStringToArray(null)).toEqual(null);
});
});
});

View File

@@ -97,6 +97,9 @@ export class Utils {
}
static fromByteStringToArray(str: string): Uint8Array {
if (str == null) {
return null;
}
const arr = new Uint8Array(str.length);
for (let i = 0; i < str.length; i++) {
arr[i] = str.charCodeAt(i);