Skip to content

Commit

Permalink
iOS: Fixed broken domain detection
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed May 29, 2023
1 parent fd578d1 commit 192bfb5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/lib/utils/webDAVUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
26 changes: 19 additions & 7 deletions packages/lib/utils/webDAVUtils.ts
Original file line number Diff line number Diff line change
@@ -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));
}
}
Expand Down

0 comments on commit 192bfb5

Please sign in to comment.