From e3576683b0be709726216517f8d1cb2b3b7c382a Mon Sep 17 00:00:00 2001 From: pedr Date: Mon, 23 Sep 2024 14:19:51 -0300 Subject: [PATCH] Desktop,Mobile,Cli: Fixes #10608: WebDAV synchronisation not working because of URL encoding differences (#11076) --- .eslintignore | 1 + .gitignore | 1 + packages/lib/file-api-driver-webdav.js | 2 ++ packages/lib/file-api-driver-webdav.test.ts | 29 +++++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 packages/lib/file-api-driver-webdav.test.ts diff --git a/.eslintignore b/.eslintignore index 2ef2e7897..232904c3e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -953,6 +953,7 @@ packages/lib/eventManager.js packages/lib/file-api-driver-joplinServer.js packages/lib/file-api-driver-local.js packages/lib/file-api-driver-memory.js +packages/lib/file-api-driver-webdav.test.js packages/lib/file-api-driver.test.js packages/lib/file-api.test.js packages/lib/file-api.js diff --git a/.gitignore b/.gitignore index e452f6c36..911a937e3 100644 --- a/.gitignore +++ b/.gitignore @@ -930,6 +930,7 @@ packages/lib/eventManager.js packages/lib/file-api-driver-joplinServer.js packages/lib/file-api-driver-local.js packages/lib/file-api-driver-memory.js +packages/lib/file-api-driver-webdav.test.js packages/lib/file-api-driver.test.js packages/lib/file-api.test.js packages/lib/file-api.js diff --git a/packages/lib/file-api-driver-webdav.js b/packages/lib/file-api-driver-webdav.js index 06b08d279..157c2131b 100644 --- a/packages/lib/file-api-driver-webdav.js +++ b/packages/lib/file-api-driver-webdav.js @@ -107,6 +107,8 @@ class FileApiDriverWebDav { output = href.substr(baseUrl.length); } else if (href.indexOf(relativeBaseUrl) === 0) { output = href.substr(relativeBaseUrl.length); + } else if (decodeURIComponent(href).indexOf(decodeURIComponent(relativeBaseUrl)) === 0) { + output = decodeURIComponent(href).substring(decodeURIComponent(relativeBaseUrl).length); } else { throw new Error(`href ${href} not in baseUrl ${baseUrl} nor relativeBaseUrl ${relativeBaseUrl}`); } diff --git a/packages/lib/file-api-driver-webdav.test.ts b/packages/lib/file-api-driver-webdav.test.ts new file mode 100644 index 000000000..cc3fe6968 --- /dev/null +++ b/packages/lib/file-api-driver-webdav.test.ts @@ -0,0 +1,29 @@ +const { FileApiDriverWebDav } = require('./file-api-driver-webdav'); + +describe('file-api-driver-webdav', () => { + + it.each([ + [ + '/remote.php/dav/files/user@mail.com/Joplin/', + '/remote.php/dav/files/user%40mail.com/Joplin', + '', + ], + [ + '/remote.php/dav/files/user@mail.com/Joplin/.lock', + '/remote.php/dav/files/user%40mail.com/Joplin', + '.lock', + ], + [ + '/remote.php/dav/files/user@mail.com/joplin%20files/locks/', + '/remote.php/dav/files/user%40mail.com/joplin files', + 'locks', + ], + ])('should return relative path even if encoding is different', (async (href: string, relativePath: string, result: string) => { + const driver = new FileApiDriverWebDav(); + + const baseUrl = 'https://use07.thegood.cloud/remote.php/dav/files/user%40mail.com/Joplin'; + + expect(driver.hrefToRelativePath_(href, baseUrl, relativePath)).toBe(result); + })); + +});