1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

iOS: Fixed broken domain detection

This commit is contained in:
Laurent Cozic 2023-05-29 12:20:56 +01:00
parent fd578d1c36
commit 192bfb5555
2 changed files with 21 additions and 9 deletions

View File

@ -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-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', () => {

View File

@ -1,18 +1,30 @@
import { _ } from '../locale';
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 => {
if (Setting.value('sync.allowUnsupportedProviders') === 1) return;
const unsupportedProviders = ['pcloud', 'jianguoyun'];
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.
// 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) {
if (pathContainsUnsupportedProvider(path, unsupportedProviders)) {
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));
}
}