Skip to content

Commit 2aa944a

Browse files
committed
fix(core): use btoa() instead of window.Buffer.from() for base64 encoding
window.Buffer is a Node.js API that is not natively available in browsers. It was apparently polyfilled in the webpack bundle by a dependency, but the polyfill is absent in environments like headless Electron (Cypress). This went undetected because browserslist-useragent-regexp < 4.1.4 had a bug where an empty browser set produced /(?:)/ (matches everything). Electron matched as "supported" and the redirect code was never reached. browserslist-useragent-regexp 4.1.4 fixed that bug (PR #1583: faithfully match an empty set of browsers), generating /[]/ instead. Electron 118 no longer matches as supported, the redirect path is now exercised, and window.Buffer.from() throws: TypeError: Cannot read properties of undefined (reading 'from') The fix replaces window.Buffer.from(str).toString('base64') with the native browser btoa(str), which has been universally available since before our minimum browser support baseline and requires no polyfill. Fixes: #57920 Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent 020c4e9 commit 2aa944a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

core/src/utils/RedirectUnsupportedBrowsers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function testSupportedBrowser() {
3333
// redirect to the unsupported warning page
3434
if (window.location.pathname.indexOf(redirectPath) === -1) {
3535
const redirectUrl = window.location.href.replace(window.location.origin, '')
36-
const base64Param = window.Buffer.from(redirectUrl).toString('base64')
36+
const base64Param = btoa(redirectUrl)
3737
history.pushState(null, null, `${redirectPath}?redirect_url=${base64Param}`)
3838
window.location.reload()
3939
}

0 commit comments

Comments
 (0)