Skip to content

Commit 7a96d53

Browse files
committed
Nc adapter: Fix handling of paths
1 parent 8e29f21 commit 7a96d53

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/lib/PathHelper.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ export default class PathHelper {
88

99
static pathToArray(path) {
1010
return this.reverseStr(path)
11-
.split(/[/](?![\\])/)
11+
.split(/[/](?![\\])|[/](?=\\\\)/)
1212
.map(value => this.reverseStr(value))
13+
.map(value => value.replace(/\\[/]/g, '/'))
14+
.map(value => value.replace(/\\\\/g, '\\'))
1315
.reverse()
1416
}
1517

1618
static arrayToPath(array) {
17-
return array.map(value => value.replace(/[/]/, '\\/')).join('/')
19+
return array
20+
.map(value => value.replace(/\\/g, '\\\\'))
21+
.map(value => value.replace(/[/]/g, '\\/'))
22+
.join('/')
1823
}
1924
}

src/lib/adapters/Nextcloud.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,24 +483,19 @@ export default class NextcloudAdapter extends Adapter {
483483
}
484484

485485
static convertPathToTag(path) {
486-
// We reverse the string and do a negative lookahead, reversing again afterwards
487486
return (
488487
TAG_PREFIX +
489-
PathHelper.pathToArray(path)
490-
.map(str => str.replace(/>/g, '\\>'))
491-
.join('>')
488+
path
489+
.replace(/[/]/g, '>')
492490
.replace(/%2C/g, '%252C')
493491
.replace(/,/g, '%2C')
494492
) // encodeURIComponent(',') == '%2C'
495493
}
496494

497495
static convertTagToPath(tag) {
498-
// We reverse the string and split using a negative lookahead, reversing again afterwards
499-
return PathHelper.reverseStr(tag.substr(TAG_PREFIX.length))
500-
.split(/>(?![\\])/)
501-
.reverse()
502-
.map(str => PathHelper.reverseStr(str).replace(/\\>/g, '>'))
503-
.join('/')
496+
return tag
497+
.substr(TAG_PREFIX.length)
498+
.replace(/>/g, '>')
504499
.replace(/%2C/g, ',') // encodeURIComponent(',') == '%2C'
505500
.replace(/%252C/g, '%2C')
506501
}

0 commit comments

Comments
 (0)