1
0
mirror of https://github.com/jiahaog/Nativefier synced 2024-06-21 07:06:35 +02:00

Remove extra whitespace in UserAgent (fix #1357, PR #1367)

Fixes https://github.com/nativefier/nativefier/issues/1357 , by
not adding a new space when removing the app name from the User-Agent.

Co-authored-by: noxafy <hci@gmx.de>
This commit is contained in:
Tedward747 2022-03-20 21:23:10 -06:00 committed by GitHub
parent 8dbe7943d4
commit 2f97a7156b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -248,9 +248,9 @@ test('getCounterValue should return a string for large counter numbers in the ti
});
describe('removeUserAgentSpecifics', () => {
const userAgentFallback =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) app-nativefier-804458/1.0.0 Chrome/89.0.4389.128 Electron/12.0.7 Safari/537.36';
test('removes Electron and App specific info', () => {
const userAgentFallback =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) app-nativefier-804458/1.0.0 Chrome/89.0.4389.128 Electron/12.0.7 Safari/537.36';
expect(
removeUserAgentSpecifics(
userAgentFallback,
@ -261,6 +261,16 @@ describe('removeUserAgentSpecifics', () => {
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36',
);
});
test('should not have multiple spaces in a row', () => {
expect(
removeUserAgentSpecifics(
userAgentFallback,
'app-nativefier-804458',
'1.0.0',
),
).toEqual(expect.not.stringMatching(/\s{2,}/));
});
});
describe('cleanupPlainText', () => {

View File

@ -183,7 +183,7 @@ export function removeUserAgentSpecifics(
// We just need to strip out the appName/1.0.0 and Electron/electronVersion
return userAgentFallback
.replace(`Electron/${process.versions.electron} `, '')
.replace(`${appName}/${appVersion} `, ' ');
.replace(`${appName}/${appVersion} `, '');
}
/** Removes extra spaces from a text */