Skip to content

Commit

Permalink
All: Fixes #61: Handle path that ends with slash for file system sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed May 8, 2018
1 parent facf8af commit cb617e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ReactNativeClient/lib/models/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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') },
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion ReactNativeClient/lib/path-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function toSystemSlashes(path, os) {
}

function rtrimSlashes(path) {
return path.replace(/\/+$/, '');
return path.replace(/[\/\\]+$/, '');
}

function ltrimSlashes(path) {
Expand Down

0 comments on commit cb617e1

Please sign in to comment.