Skip to content

Commit 397364d

Browse files
committed
add tests for recent url encoding fix for multiple + or / characters
1 parent 095713a commit 397364d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

__tests__/utils.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ describe('urlsafe_b64encode', () => {
55
it('should encode a string to base64', () => {
66
expect(urlsafe_b64encode('hello+foo/bar=====')).toBe('aGVsbG8rZm9vL2Jhcj09PT09');
77
});
8-
it('multiple characters should be encoded correctly', () => {
9-
// XXX: investigate how to produce a string that contains + or / when b64 encoded.
8+
it('multiple + characters should be encoded correctly -', () => {
9+
let inp ='const is_greater_than_1 = 45 >= 5 ? true : false\nconst is_greater_than_2 = 6435 >= 5 ? true : false';
10+
let expected = 'Y29uc3QgaXNfZ3JlYXRlcl90aGFuXzEgPSA0NSA-PSA1ID8gdHJ1ZSA6IGZhbHNlCmNvbnN0IGlzX2dyZWF0ZXJfdGhhbl8yID0gNjQzNSA-PSA1ID8gdHJ1ZSA6IGZhbHNl'
11+
expect(urlsafe_b64encode(inp)).toBe(expected);
12+
});
13+
it('multiple / characters should be encoded correctly as _', () => {
14+
let inp ='const has_env1 = window.env1 ? true : false;\nconst has_env2 = window.env2 ? true : false;';
15+
let expected = 'Y29uc3QgaGFzX2VudjEgPSB3aW5kb3cuZW52MSA_IHRydWUgOiBmYWxzZTsKY29uc3QgaGFzX2VudjIgPSB3aW5kb3cuZW52MiA_IHRydWUgOiBmYWxzZTs'
16+
expect(urlsafe_b64encode(inp)).toBe(expected);
1017
});
1118
});

0 commit comments

Comments
 (0)