From 57da8ecae7a7e63a8a449ad0d84e405b6b8664a5 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Tue, 22 Feb 2022 18:57:37 +0100 Subject: [PATCH] fix: UTF-8 encode username and password MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to support Unicode Special chars (like `é`) in username or passord, as the auth-backend decodes them using UTF-8. See https://github.com/perry-mitchell/webdav-client/issues/293 --- package-lock.json | 24 ++++++++++++++++++++ package.json | 2 ++ src/model/webdav/WebdavFileSystemProvider.ts | 5 ++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7a4f844..dec1c40 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "AGPL-3.0-or-later", "dependencies": { "carbon-components-svelte": ">=0.42.2 <1", + "utf8": "^3.0.0", "webdav": "^4.5.0" }, "devDependencies": { @@ -17,6 +18,7 @@ "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-typescript": "^8.0.0", "@tsconfig/svelte": "^2.0.0 || ^3.0.0", + "@types/utf8": "^3.0.1", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", "carbon-icons-svelte": "^10.44.4", @@ -361,6 +363,12 @@ "@types/node": "*" } }, + "node_modules/@types/utf8": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/utf8/-/utf8-3.0.1.tgz", + "integrity": "sha512-1EkWuw7rT3BMz2HpmcEOr/HL61mWNA6Ulr/KdbXR9AI0A55wD4Qfv8hizd8Q1DnknSIzzDvQmvvY/guvX7jjZA==", + "dev": true + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "5.12.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.12.0.tgz", @@ -2704,6 +2712,11 @@ "requires-port": "^1.0.0" } }, + "node_modules/utf8": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz", + "integrity": "sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==" + }, "node_modules/v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", @@ -3055,6 +3068,12 @@ "@types/node": "*" } }, + "@types/utf8": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/utf8/-/utf8-3.0.1.tgz", + "integrity": "sha512-1EkWuw7rT3BMz2HpmcEOr/HL61mWNA6Ulr/KdbXR9AI0A55wD4Qfv8hizd8Q1DnknSIzzDvQmvvY/guvX7jjZA==", + "dev": true + }, "@typescript-eslint/eslint-plugin": { "version": "5.12.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.12.0.tgz", @@ -4720,6 +4739,11 @@ "requires-port": "^1.0.0" } }, + "utf8": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz", + "integrity": "sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==" + }, "v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", diff --git a/package.json b/package.json index 6b94fd0..36aa21e 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-typescript": "^8.0.0", "@tsconfig/svelte": "^2.0.0 || ^3.0.0", + "@types/utf8": "^3.0.1", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", "carbon-icons-svelte": "^10.44.4", @@ -39,6 +40,7 @@ }, "dependencies": { "carbon-components-svelte": ">=0.42.2 <1", + "utf8": "^3.0.0", "webdav": "^4.5.0" }, "repository": { diff --git a/src/model/webdav/WebdavFileSystemProvider.ts b/src/model/webdav/WebdavFileSystemProvider.ts index 24592bb..f7ae398 100644 --- a/src/model/webdav/WebdavFileSystemProvider.ts +++ b/src/model/webdav/WebdavFileSystemProvider.ts @@ -2,6 +2,7 @@ import { AuthType, createClient } from "webdav/web"; import type { FileSystem } from "../FileSystem"; import type { FileSystemProvider } from "../FileSystemProvider"; import { WebdavFileSystem } from "./WebdavFileSystem"; +import { encode } from "utf8"; export class WebdavFileSystemProvider implements FileSystemProvider { constructor( @@ -13,8 +14,8 @@ export class WebdavFileSystemProvider implements FileSystemProvider { async getFileSystem(username: string, password: string): Promise { const client = createClient(this.serverUrl, { authType: this.authType, - username: username, - password: password, + username: encode(username), + password: encode(password), }); const root = this.root.replace("{username}", username); if (!await client.exists(root)) {