Skip to content

Commit d244f6d

Browse files
committed
fix(SyncProcess): Fix URL collisions on NC Bookmarks
Signed-off-by: Marcel Klehr <[email protected]>
1 parent e3e6b93 commit d244f6d

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/lib/strategies/Default.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,18 +487,47 @@ export default class SyncProcess {
487487
localScanner = new Scanner(
488488
this.cacheTreeRoot,
489489
this.localTreeRoot,
490-
(oldItem, newItem) =>
491-
(oldItem.type === newItem.type && String(oldItem.id) === String(newItem.id)),
490+
(oldItem, newItem) => {
491+
if (oldItem.type !== newItem.type) {
492+
return false
493+
}
494+
if (oldItem.type === 'folder') {
495+
if (String(oldItem.id) === String(newItem.id)) {
496+
return true
497+
}
498+
}
499+
if (oldItem.type === 'bookmark' && newItem.type === 'bookmark') {
500+
if (String(oldItem.id) === String(newItem.id) && oldItem.url === newItem.url) {
501+
return true
502+
}
503+
}
504+
return false
505+
},
492506
this.preserveOrder
493507
)
494508
serverScanner = new Scanner(
495509
this.cacheTreeRoot,
496510
this.serverTreeRoot,
497511
// We also allow canMergeWith here, because e.g. for NextcloudFolders the id of moved bookmarks changes (because their id is "<bookmarkID>;<folderId>")
498512
(oldItem, newItem) => {
499-
if ((oldItem.type === newItem.type && Mappings.mappable(mappingsSnapshot, oldItem, newItem)) || (oldItem.type === 'bookmark' && oldItem.canMergeWith(newItem))) {
500-
newMappings.push([oldItem, newItem])
501-
return true
513+
if (oldItem.type !== newItem.type) {
514+
return false
515+
}
516+
if (oldItem.type === 'folder') {
517+
if (Mappings.mappable(mappingsSnapshot, oldItem, newItem)) {
518+
newMappings.push([oldItem, newItem])
519+
return true
520+
}
521+
}
522+
if (oldItem.type === 'bookmark' && newItem.type === 'bookmark') {
523+
if (Mappings.mappable(mappingsSnapshot, oldItem, newItem) && oldItem.url === newItem.url) {
524+
newMappings.push([oldItem, newItem])
525+
return true
526+
}
527+
if (oldItem.canMergeWith(newItem)) {
528+
newMappings.push([oldItem, newItem])
529+
return true
530+
}
502531
}
503532
return false
504533
},
@@ -882,7 +911,6 @@ export default class SyncProcess {
882911
}
883912

884913
if (action.payload instanceof Folder && action.payload.children.length && action.oldItem instanceof Folder) {
885-
886914
// Fix for Unidirectional reverted REMOVEs, for all other strategies this should be a noop
887915
action.payload.children.forEach((item) => {
888916
item.parentId = id

src/test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5284,8 +5284,8 @@ describe('Floccus', function() {
52845284
new Folder({
52855285
title: 'Window 0',
52865286
children: [
5287-
new Bookmark({ title: 'Example Domain', url: 'https://example.org/#test3' }),
52885287
new Bookmark({ title: 'Example Domain', url: 'https://example.org/#test2' }),
5288+
new Bookmark({ title: 'Example Domain', url: 'https://example.org/#test3' }),
52895289
new Bookmark({ title: 'Example Domain', url: 'https://example.org/#test4' }),
52905290
]
52915291
})

0 commit comments

Comments
 (0)