Skip to content

Fix IE11 broken by Crypto change. #2832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/firestore/src/platform_browser/browser_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class BrowserPlatform implements Platform {
}

const v = new Uint8Array(nBytes);
// Polyfill for IE11.
const crypto = window.crypto || (window as any).msCrypto;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably need to suppress eslint here to pass tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you could do this once at the top of the file (after imports before the class).

crypto.getRandomValues(v);
return v;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/src/util/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export class AutoId {
let autoId = '';
while (autoId.length < 20) {
const bytes = PlatformSupport.getPlatform().randomBytes(40);
bytes.forEach(b => {
for (const b of Array.from(bytes)) {
// Length of `chars` is 62. We only take bytes between 0 and 62*4-1
// (both inclusive). The value is then evenly mapped to indices of `char`
// via a modulo operation.
const maxValue = 62 * 4 - 1;
if (autoId.length < 20 && b <= maxValue) {
autoId += chars.charAt(b % 62);
}
});
}
}
assert(autoId.length === 20, 'Invalid auto ID: ' + autoId);
return autoId;
Expand Down