From cb617e1b1439df516a09f0899fdeda7f0f91087c Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 8 May 2018 11:29:25 +0100 Subject: [PATCH] All: Fixes #61: Handle path that ends with slash for file system sync. --- ReactNativeClient/lib/models/Setting.js | 10 ++++++++++ ReactNativeClient/lib/path-utils.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ReactNativeClient/lib/models/Setting.js b/ReactNativeClient/lib/models/Setting.js index 730c4d9c01b..837a991f1a2 100644 --- a/ReactNativeClient/lib/models/Setting.js +++ b/ReactNativeClient/lib/models/Setting.js @@ -6,6 +6,7 @@ const { time } = require('lib/time-utils.js'); const { sprintf } = require('sprintf-js'); const ObjectUtils = require('lib/ObjectUtils'); const { toTitleCase } = require('lib/string-utils.js'); +const { rtrimSlashes } = require('lib/path-utils.js'); const { _, supportedLocalesToLanguages, defaultLocale } = require('lib/locale.js'); const { shim } = require('lib/shim'); @@ -122,6 +123,8 @@ class Setting extends BaseModel { } catch (error) { return false; } + }, filter: (value) => { + return value ? rtrimSlashes(value) : ''; }, public: true, label: () => _('Directory to synchronise with (absolute path)'), description: (appType) => { return appType !== 'cli' ? null : _('The path to synchronise with when file system synchronisation is enabled. See `sync.target`.'); } }, 'sync.5.path': { value: '', type: Setting.TYPE_STRING, show: (settings) => { return settings['sync.target'] == SyncTargetRegistry.nameToId('nextcloud') }, public: true, label: () => _('Nextcloud WebDAV URL') }, @@ -204,6 +207,7 @@ class Setting extends BaseModel { if (!this.keyExists(c.key)) continue; c.value = this.formatValue(c.key, c.value); + c.value = this.filterValue(c.key, c.value); this.cache_.push(c); } @@ -237,6 +241,7 @@ class Setting extends BaseModel { if (!this.cache_) throw new Error('Settings have not been initialized!'); value = this.formatValue(key, value); + value = this.filterValue(key, value); for (let i = 0; i < this.cache_.length; i++) { let c = this.cache_[i]; @@ -307,6 +312,11 @@ class Setting extends BaseModel { throw new Error('Unhandled value type: ' + md.type); } + static filterValue(key, value) { + const md = this.settingMetadata(key); + return md.filter ? md.filter(value) : value; + } + static formatValue(key, value) { const md = this.settingMetadata(key); diff --git a/ReactNativeClient/lib/path-utils.js b/ReactNativeClient/lib/path-utils.js index 5dfbbebd232..13f2053a621 100644 --- a/ReactNativeClient/lib/path-utils.js +++ b/ReactNativeClient/lib/path-utils.js @@ -46,7 +46,7 @@ function toSystemSlashes(path, os) { } function rtrimSlashes(path) { - return path.replace(/\/+$/, ''); + return path.replace(/[\/\\]+$/, ''); } function ltrimSlashes(path) {