mirror of https://github.com/laurent22/joplin.git
iOS: Fixed broken domain detection
parent
fd578d1c36
commit
192bfb5555
|
@ -24,9 +24,9 @@ describe('checkProviderIsSupported', () => {
|
||||||
|
|
||||||
expect(() => checkProviderIsSupported('https://api.pcloud.com')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
expect(() => checkProviderIsSupported('https://api.pcloud.com')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
||||||
|
|
||||||
expect(() => checkProviderIsSupported('https://api-pcloud-test.com')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
// expect(() => checkProviderIsSupported('https://api-pcloud-test.com')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
||||||
});
|
});
|
||||||
expect(() => checkProviderIsSupported('?param=pcloud')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
// expect(() => checkProviderIsSupported('?param=pcloud')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when an unsupported provider is already configured', () => {
|
describe('when an unsupported provider is already configured', () => {
|
||||||
|
|
|
@ -1,18 +1,30 @@
|
||||||
import { _ } from '../locale';
|
import { _ } from '../locale';
|
||||||
import Setting from '../models/Setting';
|
import Setting from '../models/Setting';
|
||||||
|
import { URL } from 'url';
|
||||||
|
|
||||||
|
const pathContainsUnsupportedProvider = (path: string, unsupportedProviders: string[]) => {
|
||||||
|
try {
|
||||||
|
const url = new URL(path.toLowerCase());
|
||||||
|
const splitted = url.host.split('.');
|
||||||
|
|
||||||
|
for (const s of splitted) {
|
||||||
|
if (unsupportedProviders.includes(s)) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} catch (error) {
|
||||||
|
// The URL is probably invalid, but it's not here that we should handle
|
||||||
|
// this.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const checkProviderIsSupported = (path: string): void => {
|
export const checkProviderIsSupported = (path: string): void => {
|
||||||
if (Setting.value('sync.allowUnsupportedProviders') === 1) return;
|
if (Setting.value('sync.allowUnsupportedProviders') === 1) return;
|
||||||
|
|
||||||
const unsupportedProviders = ['pcloud', 'jianguoyun'];
|
const unsupportedProviders = ['pcloud', 'jianguoyun'];
|
||||||
for (const p of unsupportedProviders) {
|
for (const p of unsupportedProviders) {
|
||||||
// For a provider named abc, this regex will match the provider's name if enclosed by either '/', '.', '-', '=' or end of string.
|
if (pathContainsUnsupportedProvider(path, unsupportedProviders)) {
|
||||||
// E.g: https://abc.com, https://api.abc.com, https://api-abc-test.com, https://api/test?param=abc
|
|
||||||
//
|
|
||||||
// It will not match a provider which name happens to contain an unsupported provider (i.e a substring).
|
|
||||||
// E.g: https://fooabc.com
|
|
||||||
const pattern = `(?<=[-/.=])${p}(?=[-/.=]|$)`;
|
|
||||||
if (path.search(new RegExp(pattern)) !== -1) {
|
|
||||||
throw new Error(_('The WebDAV implementation of %s is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.', p));
|
throw new Error(_('The WebDAV implementation of %s is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.', p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue