mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-12-22 18:18:55 +00:00
Make eslint happy
This commit is contained in:
parent
6b6ef1d12d
commit
347df98c77
@ -6,89 +6,118 @@ import {
|
||||
|
||||
const internalUrl = 'https://medium.com/';
|
||||
const internalUrlWww = 'https://www.medium.com/';
|
||||
const internalUrlSubPathRegex = /https\:\/\/www.medium.com\/.*/;
|
||||
const internalUrlSubPathRegex = /https:\/\/www.medium.com\/.*/;
|
||||
const sameBaseDomainUrl = 'https://app.medium.com/';
|
||||
const internalUrlCoUk = 'https://medium.co.uk/';
|
||||
const differentBaseDomainUrlCoUk = 'https://other.domain.co.uk/';
|
||||
const sameBaseDomainUrlCoUk = 'https://app.medium.co.uk/';
|
||||
const sameBaseDomainUrlTidalListen = 'https://listen.tidal.com/';
|
||||
const sameBaseDomainUrlTidalLogin = 'https://login.tidal.com/';
|
||||
const sameBaseDomainUrlTidalRegex = /https\:\/\/(login|listen).tidal.com\/.*/;
|
||||
const sameBaseDomainUrlTidalRegex = /https:\/\/(login|listen).tidal.com\/.*/;
|
||||
const internalUrlSubPath = 'topic/technology';
|
||||
const externalUrl = 'https://www.wikipedia.org/wiki/Electron';
|
||||
const wildcardRegex = /.*/;
|
||||
|
||||
test('the original url should be internal without --strict-internal-urls', () => {
|
||||
expect(linkIsInternal(internalUrl, internalUrl, undefined, undefined)).toEqual(true);
|
||||
expect(
|
||||
linkIsInternal(internalUrl, internalUrl, undefined, undefined),
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('the original url should be internal with --strict-internal-urls off', () => {
|
||||
expect(linkIsInternal(internalUrl, internalUrl, undefined, false)).toEqual(true);
|
||||
expect(linkIsInternal(internalUrl, internalUrl, undefined, false)).toEqual(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('the original url should be internal with --strict-internal-urls on', () => {
|
||||
expect(linkIsInternal(internalUrl, internalUrl, undefined, true)).toEqual(true);
|
||||
expect(linkIsInternal(internalUrl, internalUrl, undefined, true)).toEqual(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('sub-paths of the original url should be internal with --strict-internal-urls off', () => {
|
||||
expect(
|
||||
linkIsInternal(internalUrl, internalUrl + internalUrlSubPath, undefined, false),
|
||||
linkIsInternal(
|
||||
internalUrl,
|
||||
internalUrl + internalUrlSubPath,
|
||||
undefined,
|
||||
false,
|
||||
),
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('sub-paths of the original url should not be internal with --strict-internal-urls on', () => {
|
||||
expect(
|
||||
linkIsInternal(internalUrl, internalUrl + internalUrlSubPath, undefined, true),
|
||||
linkIsInternal(
|
||||
internalUrl,
|
||||
internalUrl + internalUrlSubPath,
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
test('sub-paths of the original url should be internal with using a regex and --strict-internal-urls on', () => {
|
||||
expect(
|
||||
linkIsInternal(internalUrl, internalUrl + internalUrlSubPath, internalUrlSubPathRegex, true),
|
||||
linkIsInternal(
|
||||
internalUrl,
|
||||
internalUrl + internalUrlSubPath,
|
||||
internalUrlSubPathRegex,
|
||||
true,
|
||||
),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
test("'about:blank' should always be internal", () => {
|
||||
expect(linkIsInternal(internalUrl, 'about:blank', undefined, true)).toEqual(true);
|
||||
});
|
||||
|
||||
test('urls from different sites should not be internal', () => {
|
||||
expect(linkIsInternal(internalUrl, externalUrl, undefined, false)).toEqual(false);
|
||||
});
|
||||
|
||||
test('all urls should be internal with wildcard regex', () => {
|
||||
expect(linkIsInternal(internalUrl, externalUrl, wildcardRegex, true)).toEqual(true);
|
||||
});
|
||||
|
||||
test('a "www." of a domain should be considered internal', () => {
|
||||
expect(linkIsInternal(internalUrl, internalUrlWww, undefined, false)).toEqual(true);
|
||||
});
|
||||
|
||||
test('urls on the same "base domain" should be considered internal', () => {
|
||||
expect(linkIsInternal(internalUrl, sameBaseDomainUrl, undefined, false)).toEqual(
|
||||
expect(linkIsInternal(internalUrl, 'about:blank', undefined, true)).toEqual(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('urls on the same "base domain" should NOT be considered internal using --strict-internal-urls', () => {
|
||||
expect(linkIsInternal(internalUrl, sameBaseDomainUrl, undefined, true)).toEqual(
|
||||
test('urls from different sites should not be internal', () => {
|
||||
expect(linkIsInternal(internalUrl, externalUrl, undefined, false)).toEqual(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('urls on the same "base domain" should be considered internal, even with a www', () => {
|
||||
expect(linkIsInternal(internalUrlWww, sameBaseDomainUrl, undefined, false)).toEqual(
|
||||
test('all urls should be internal with wildcard regex', () => {
|
||||
expect(linkIsInternal(internalUrl, externalUrl, wildcardRegex, true)).toEqual(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('a "www." of a domain should be considered internal', () => {
|
||||
expect(linkIsInternal(internalUrl, internalUrlWww, undefined, false)).toEqual(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('urls on the same "base domain" should be considered internal', () => {
|
||||
expect(
|
||||
linkIsInternal(internalUrl, sameBaseDomainUrl, undefined, false),
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('urls on the same "base domain" should NOT be considered internal using --strict-internal-urls', () => {
|
||||
expect(
|
||||
linkIsInternal(internalUrl, sameBaseDomainUrl, undefined, true),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
test('urls on the same "base domain" should be considered internal, even with a www', () => {
|
||||
expect(
|
||||
linkIsInternal(internalUrlWww, sameBaseDomainUrl, undefined, false),
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('urls on the same "base domain" should be considered internal, even with different sub domains', () => {
|
||||
expect(
|
||||
linkIsInternal(
|
||||
sameBaseDomainUrlTidalListen,
|
||||
sameBaseDomainUrlTidalLogin,
|
||||
undefined,
|
||||
false
|
||||
false,
|
||||
),
|
||||
).toEqual(true);
|
||||
});
|
||||
@ -99,7 +128,7 @@ test('urls should support sub domain matching with a regex', () => {
|
||||
sameBaseDomainUrlTidalListen,
|
||||
sameBaseDomainUrlTidalLogin,
|
||||
sameBaseDomainUrlTidalRegex,
|
||||
false
|
||||
false,
|
||||
),
|
||||
).toEqual(true);
|
||||
});
|
||||
@ -110,12 +139,11 @@ test('urls on the same "base domain" should NOT be considered internal with diff
|
||||
sameBaseDomainUrlTidalListen,
|
||||
sameBaseDomainUrlTidalLogin,
|
||||
undefined,
|
||||
true
|
||||
true,
|
||||
),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
|
||||
test('urls on the same "base domain" should be considered internal, long SLD', () => {
|
||||
expect(
|
||||
linkIsInternal(internalUrlCoUk, sameBaseDomainUrlCoUk, undefined, false),
|
||||
@ -124,7 +152,12 @@ test('urls on the same "base domain" should be considered internal, long SLD', (
|
||||
|
||||
test('urls on the a different "base domain" are considered NOT internal, long SLD', () => {
|
||||
expect(
|
||||
linkIsInternal(internalUrlCoUk, differentBaseDomainUrlCoUk, undefined, false),
|
||||
linkIsInternal(
|
||||
internalUrlCoUk,
|
||||
differentBaseDomainUrlCoUk,
|
||||
undefined,
|
||||
false,
|
||||
),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
@ -171,7 +204,9 @@ const testLoginPages = [
|
||||
test.each(testLoginPages)(
|
||||
'%s login page should be internal',
|
||||
(loginUrl: string) => {
|
||||
expect(linkIsInternal(internalUrl, loginUrl, undefined, false)).toEqual(true);
|
||||
expect(linkIsInternal(internalUrl, loginUrl, undefined, false)).toEqual(
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -137,7 +137,7 @@ export function linkIsInternal(
|
||||
if (isStrictInternalUrlsEnabled) {
|
||||
return currentUrl == newUrl;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// Consider as "same domain-ish", without TLD/SLD list:
|
||||
// 1. app.foo.com and foo.com
|
||||
|
@ -73,7 +73,14 @@ export function onNewWindowHelper(
|
||||
parent,
|
||||
});
|
||||
try {
|
||||
if (!linkIsInternal(options.targetUrl, urlToGo, options.internalUrls, options.strictInternalUrls)) {
|
||||
if (
|
||||
!linkIsInternal(
|
||||
options.targetUrl,
|
||||
urlToGo,
|
||||
options.internalUrls,
|
||||
options.strictInternalUrls,
|
||||
)
|
||||
) {
|
||||
preventDefault();
|
||||
if (options.blockExternalUrls) {
|
||||
return new Promise((resolve) => {
|
||||
@ -121,7 +128,14 @@ export function onWillNavigate(
|
||||
urlToGo: string,
|
||||
): Promise<void> {
|
||||
log.debug('onWillNavigate', { options, event, urlToGo });
|
||||
if (!linkIsInternal(options.targetUrl, urlToGo, options.internalUrls, options.strictInternalUrls)) {
|
||||
if (
|
||||
!linkIsInternal(
|
||||
options.targetUrl,
|
||||
urlToGo,
|
||||
options.internalUrls,
|
||||
options.strictInternalUrls,
|
||||
)
|
||||
) {
|
||||
event.preventDefault();
|
||||
if (options.blockExternalUrls) {
|
||||
return new Promise((resolve) => {
|
||||
|
13
src/cli.ts
13
src/cli.ts
@ -347,14 +347,12 @@ export function initArgs(argv: string[]): yargs.Argv<RawOptions> {
|
||||
})
|
||||
.option('internal-urls', {
|
||||
defaultDescription: 'URLs sharing the same base domain',
|
||||
description:
|
||||
`regex of URLs to consider "internal"; by default matches based on domain (see '--strict-internal-urls'); all other URLs will be opened in an external browser`,
|
||||
description: `regex of URLs to consider "internal"; by default matches based on domain (see '--strict-internal-urls'); all other URLs will be opened in an external browser`,
|
||||
type: 'string',
|
||||
})
|
||||
.option('strict-internal-urls', {
|
||||
default: false,
|
||||
description:
|
||||
'disable domain-based matching on internal URLs',
|
||||
description: 'disable domain-based matching on internal URLs',
|
||||
type: 'boolean',
|
||||
})
|
||||
.option('proxy-rules', {
|
||||
@ -363,7 +361,12 @@ export function initArgs(argv: string[]): yargs.Argv<RawOptions> {
|
||||
type: 'string',
|
||||
})
|
||||
.group(
|
||||
['block-external-urls', 'internal-urls', 'strict-internal-urls', 'proxy-rules'],
|
||||
[
|
||||
'block-external-urls',
|
||||
'internal-urls',
|
||||
'strict-internal-urls',
|
||||
'proxy-rules',
|
||||
],
|
||||
decorateYargOptionGroup('URL Handling Options'),
|
||||
)
|
||||
// Auth Options
|
||||
|
Loading…
Reference in New Issue
Block a user