refactor: use replaceAll()
instead of replace()
when appropriate (#39721)
refactor: use replaceAll() instead of replace() when appropriate
This commit is contained in:
parent
029127a8b6
commit
f6e8544ef6
10 changed files with 20 additions and 20 deletions
|
@ -33,7 +33,7 @@ const normalizeAccessKey = (text: string) => {
|
||||||
// macOS does not have access keys so remove single ampersands
|
// macOS does not have access keys so remove single ampersands
|
||||||
// and replace double ampersands with a single ampersand
|
// and replace double ampersands with a single ampersand
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
return text.replace(/&(&?)/g, '$1');
|
return text.replaceAll(/&(&?)/g, '$1');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux uses a single underscore as an access key prefix so escape
|
// Linux uses a single underscore as an access key prefix so escape
|
||||||
|
@ -41,7 +41,7 @@ const normalizeAccessKey = (text: string) => {
|
||||||
// ampersands with a single ampersand, and replace a single ampersand with
|
// ampersands with a single ampersand, and replace a single ampersand with
|
||||||
// a single underscore
|
// a single underscore
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
return text.replace(/_/g, '__').replace(/&(.?)/g, (match, after) => {
|
return text.replaceAll('_', '__').replaceAll(/&(.?)/g, (match, after) => {
|
||||||
if (after === '&') return after;
|
if (after === '&') return after;
|
||||||
return `_${after}`;
|
return `_${after}`;
|
||||||
});
|
});
|
||||||
|
|
|
@ -63,8 +63,8 @@ if (process.platform === 'win32') {
|
||||||
|
|
||||||
if (fs.existsSync(updateDotExe)) {
|
if (fs.existsSync(updateDotExe)) {
|
||||||
const packageDir = path.dirname(path.resolve(updateDotExe));
|
const packageDir = path.dirname(path.resolve(updateDotExe));
|
||||||
const packageName = path.basename(packageDir).replace(/\s/g, '');
|
const packageName = path.basename(packageDir).replaceAll(/\s/g, '');
|
||||||
const exeName = path.basename(process.execPath).replace(/\.exe$/i, '').replace(/\s/g, '');
|
const exeName = path.basename(process.execPath).replace(/\.exe$/i, '').replaceAll(/\s/g, '');
|
||||||
|
|
||||||
app.setAppUserModelId(`com.squirrel.${packageName}.${exeName}`);
|
app.setAppUserModelId(`com.squirrel.${packageName}.${exeName}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3425,7 +3425,7 @@ describe('BrowserWindow module', () => {
|
||||||
w.loadURL(pageUrl);
|
w.loadURL(pageUrl);
|
||||||
const [, url] = await once(ipcMain, 'answer');
|
const [, url] = await once(ipcMain, 'answer');
|
||||||
const expectedUrl = process.platform === 'win32'
|
const expectedUrl = process.platform === 'win32'
|
||||||
? 'file:///' + htmlPath.replace(/\\/g, '/')
|
? 'file:///' + htmlPath.replaceAll('\\', '/')
|
||||||
: pageUrl;
|
: pageUrl;
|
||||||
expect(url).to.equal(expectedUrl);
|
expect(url).to.equal(expectedUrl);
|
||||||
});
|
});
|
||||||
|
@ -3475,7 +3475,7 @@ describe('BrowserWindow module', () => {
|
||||||
w.loadURL(pageUrl);
|
w.loadURL(pageUrl);
|
||||||
const [, { url, frameName, options }] = await once(w.webContents, 'did-create-window') as [BrowserWindow, Electron.DidCreateWindowDetails];
|
const [, { url, frameName, options }] = await once(w.webContents, 'did-create-window') as [BrowserWindow, Electron.DidCreateWindowDetails];
|
||||||
const expectedUrl = process.platform === 'win32'
|
const expectedUrl = process.platform === 'win32'
|
||||||
? 'file:///' + htmlPath.replace(/\\/g, '/')
|
? 'file:///' + htmlPath.replaceAll('\\', '/')
|
||||||
: pageUrl;
|
: pageUrl;
|
||||||
expect(url).to.equal(expectedUrl);
|
expect(url).to.equal(expectedUrl);
|
||||||
expect(frameName).to.equal('popup!');
|
expect(frameName).to.equal('popup!');
|
||||||
|
|
|
@ -111,7 +111,7 @@ describe('debugger module', () => {
|
||||||
it('fires message event', async () => {
|
it('fires message event', async () => {
|
||||||
const url = process.platform !== 'win32'
|
const url = process.platform !== 'win32'
|
||||||
? `file://${path.join(fixtures, 'pages', 'a.html')}`
|
? `file://${path.join(fixtures, 'pages', 'a.html')}`
|
||||||
: `file:///${path.join(fixtures, 'pages', 'a.html').replace(/\\/g, '/')}`;
|
: `file:///${path.join(fixtures, 'pages', 'a.html').replaceAll('\\', '/')}`;
|
||||||
w.webContents.loadURL(url);
|
w.webContents.loadURL(url);
|
||||||
w.webContents.debugger.attach();
|
w.webContents.debugger.attach();
|
||||||
const message = emittedUntil(w.webContents.debugger, 'message',
|
const message = emittedUntil(w.webContents.debugger, 'message',
|
||||||
|
|
|
@ -1128,7 +1128,7 @@ describe('protocol module', () => {
|
||||||
protocol.handle('file', (req) => {
|
protocol.handle('file', (req) => {
|
||||||
let file;
|
let file;
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
file = `file:///${filePath.replace(/\\/g, '/')}`;
|
file = `file:///${filePath.replaceAll('\\', '/')}`;
|
||||||
} else {
|
} else {
|
||||||
file = `file://${filePath}`;
|
file = `file://${filePath}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,7 +237,7 @@ describe('session module', () => {
|
||||||
|
|
||||||
appProcess.stdout.on('data', data => { output += data; });
|
appProcess.stdout.on('data', data => { output += data; });
|
||||||
appProcess.on('exit', () => {
|
appProcess.on('exit', () => {
|
||||||
resolve(output.replace(/(\r\n|\n|\r)/gm, ''));
|
resolve(output.replaceAll(/(\r\n|\n|\r)/gm, ''));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -181,7 +181,7 @@ describe('webRequest module', () => {
|
||||||
callback({ cancel: true });
|
callback({ cancel: true });
|
||||||
});
|
});
|
||||||
const fileURL = url.format({
|
const fileURL = url.format({
|
||||||
pathname: path.join(fixturesPath, 'blank.html').replace(/\\/g, '/'),
|
pathname: path.join(fixturesPath, 'blank.html').replaceAll('\\', '/'),
|
||||||
protocol: 'file',
|
protocol: 'file',
|
||||||
slashes: true
|
slashes: true
|
||||||
});
|
});
|
||||||
|
@ -395,7 +395,7 @@ describe('webRequest module', () => {
|
||||||
onSendHeadersCalled = true;
|
onSendHeadersCalled = true;
|
||||||
});
|
});
|
||||||
await ajax(url.format({
|
await ajax(url.format({
|
||||||
pathname: path.join(fixturesPath, 'blank.html').replace(/\\/g, '/'),
|
pathname: path.join(fixturesPath, 'blank.html').replaceAll('\\', '/'),
|
||||||
protocol: 'file',
|
protocol: 'file',
|
||||||
slashes: true
|
slashes: true
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -90,7 +90,7 @@ describe('asar package', () => {
|
||||||
await w.loadFile(path.join(fixtures, 'workers', 'load_worker.html'));
|
await w.loadFile(path.join(fixtures, 'workers', 'load_worker.html'));
|
||||||
|
|
||||||
const workerUrl = url.format({
|
const workerUrl = url.format({
|
||||||
pathname: path.resolve(fixtures, 'workers', 'workers.asar', 'worker.js').replace(/\\/g, '/'),
|
pathname: path.resolve(fixtures, 'workers', 'workers.asar', 'worker.js').replaceAll('\\', '/'),
|
||||||
protocol: 'file',
|
protocol: 'file',
|
||||||
slashes: true
|
slashes: true
|
||||||
});
|
});
|
||||||
|
@ -103,7 +103,7 @@ describe('asar package', () => {
|
||||||
await w.loadFile(path.join(fixtures, 'workers', 'load_shared_worker.html'));
|
await w.loadFile(path.join(fixtures, 'workers', 'load_shared_worker.html'));
|
||||||
|
|
||||||
const workerUrl = url.format({
|
const workerUrl = url.format({
|
||||||
pathname: path.resolve(fixtures, 'workers', 'workers.asar', 'shared_worker.js').replace(/\\/g, '/'),
|
pathname: path.resolve(fixtures, 'workers', 'workers.asar', 'shared_worker.js').replaceAll('\\', '/'),
|
||||||
protocol: 'file',
|
protocol: 'file',
|
||||||
slashes: true
|
slashes: true
|
||||||
});
|
});
|
||||||
|
@ -1243,7 +1243,7 @@ describe('asar package', function () {
|
||||||
const echo = path.join(asarDir, 'echo.asar', 'echo');
|
const echo = path.join(asarDir, 'echo.asar', 'echo');
|
||||||
|
|
||||||
const stdout = await promisify(require(childProcess).exec)('echo ' + echo + ' foo bar');
|
const stdout = await promisify(require(childProcess).exec)('echo ' + echo + ' foo bar');
|
||||||
expect(stdout.toString().replace(/\r/g, '')).to.equal(echo + ' foo bar\n');
|
expect(stdout.toString().replaceAll('\r', '')).to.equal(echo + ' foo bar\n');
|
||||||
}, [childProcess]);
|
}, [childProcess]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1252,7 +1252,7 @@ describe('asar package', function () {
|
||||||
const echo = path.join(asarDir, 'echo.asar', 'echo');
|
const echo = path.join(asarDir, 'echo.asar', 'echo');
|
||||||
|
|
||||||
const stdout = require(childProcess).execSync('echo ' + echo + ' foo bar');
|
const stdout = require(childProcess).execSync('echo ' + echo + ' foo bar');
|
||||||
expect(stdout.toString().replace(/\r/g, '')).to.equal(echo + ' foo bar\n');
|
expect(stdout.toString().replaceAll('\r', '')).to.equal(echo + ' foo bar\n');
|
||||||
}, [childProcess]);
|
}, [childProcess]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -284,7 +284,7 @@ describe('web security', () => {
|
||||||
describe('accessing file://', () => {
|
describe('accessing file://', () => {
|
||||||
async function loadFile (w: BrowserWindow) {
|
async function loadFile (w: BrowserWindow) {
|
||||||
const thisFile = url.format({
|
const thisFile = url.format({
|
||||||
pathname: __filename.replace(/\\/g, '/'),
|
pathname: __filename.replaceAll('\\', '/'),
|
||||||
protocol: 'file',
|
protocol: 'file',
|
||||||
slashes: true
|
slashes: true
|
||||||
});
|
});
|
||||||
|
@ -461,7 +461,7 @@ describe('command line switches', () => {
|
||||||
throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
|
throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
output = output.replace(/(\r\n|\n|\r)/gm, '');
|
output = output.replaceAll(/(\r\n|\n|\r)/gm, '');
|
||||||
expect(output).to.equal(result);
|
expect(output).to.equal(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1050,7 +1050,7 @@ describe('chromium features', () => {
|
||||||
it('defines a window.location getter', async () => {
|
it('defines a window.location getter', async () => {
|
||||||
let targetURL: string;
|
let targetURL: string;
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
targetURL = `file:///${fixturesPath.replace(/\\/g, '/')}/pages/base-page.html`;
|
targetURL = `file:///${fixturesPath.replaceAll('\\', '/')}/pages/base-page.html`;
|
||||||
} else {
|
} else {
|
||||||
targetURL = `file://${fixturesPath}/pages/base-page.html`;
|
targetURL = `file://${fixturesPath}/pages/base-page.html`;
|
||||||
}
|
}
|
||||||
|
@ -1977,7 +1977,7 @@ describe('chromium features', () => {
|
||||||
|
|
||||||
ifdescribe(features.isPDFViewerEnabled())('PDF Viewer', () => {
|
ifdescribe(features.isPDFViewerEnabled())('PDF Viewer', () => {
|
||||||
const pdfSource = url.format({
|
const pdfSource = url.format({
|
||||||
pathname: path.join(__dirname, 'fixtures', 'cat.pdf').replace(/\\/g, '/'),
|
pathname: path.join(__dirname, 'fixtures', 'cat.pdf').replaceAll('\\', '/'),
|
||||||
protocol: 'file',
|
protocol: 'file',
|
||||||
slashes: true
|
slashes: true
|
||||||
});
|
});
|
||||||
|
|
|
@ -249,7 +249,7 @@ describe('<webview> tag', function () {
|
||||||
});
|
});
|
||||||
await w.loadURL('about:blank');
|
await w.loadURL('about:blank');
|
||||||
const src = url.format({
|
const src = url.format({
|
||||||
pathname: `${fixtures.replace(/\\/g, '/')}/pages/theme-color.html`,
|
pathname: `${fixtures.replaceAll('\\', '/')}/pages/theme-color.html`,
|
||||||
protocol: 'file',
|
protocol: 'file',
|
||||||
slashes: true
|
slashes: true
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue