Skip to content

Commit

Permalink
fix: Always cast to string before comparing item ids
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Dec 10, 2023
1 parent 729f6d2 commit 93202b2
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/lib/Diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default class Diff {
const DAG = folderMoves
.reduce((DAG, action1) => {
DAG[action1.payload.id] = folderMoves.filter(action2 => {
if (action1 === action2 || action1.payload.id === action2.payload.id) {
if (action1 === action2 || String(action1.payload.id) === String(action2.payload.id)) {
return false
}
return (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/LocalTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class LocalTabs implements IResource {
// Not perfect but good enough (Problem: [a,X,c] => insert(b,0) => [b, X, a, c])
if (originalTabs.length !== order.length) {
const untouchedChildren = originalTabs.map((tab, i) => [i, tab]).filter(([, tab]) =>
!order.some(item => tab.id === item.id)
!order.some(item => String(tab.id) === String(item.id))
)
try {
for (const [index, child] of untouchedChildren) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default class Scanner {
const moves = this.diff.getActions(ActionType.MOVE)
const updates = this.diff.getActions(ActionType.UPDATE)
updates.forEach(update => {
if (moves.find(move => move.payload.id === update.payload.id)) {
if (moves.find(move => String(move.payload.id) === String(update.payload.id))) {
this.diff.retract(update)
}
})
Expand Down Expand Up @@ -265,7 +265,7 @@ export default class Scanner {

for (const folderId in targets) {
const newFolder = this.newTree.findItem(ItemType.FOLDER, folderId) as Folder
const duplicate = this.diff.getActions(ActionType.REORDER).find(a => a.payload.id === newFolder.id)
const duplicate = this.diff.getActions(ActionType.REORDER).find(a => String(a.payload.id) === String(newFolder.id))
if (duplicate) {
this.diff.retract(duplicate)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class Folder {
static getAncestorsOf(item: TItem, tree: Folder): TItem[] {
const ancestors = [item]
let parent = item
while (parent.id !== tree.id) {
while (String(parent.id) !== String(tree.id)) {
ancestors.push(parent)
parent = tree.findItem(ItemType.FOLDER, parent.parentId)
if (!parent) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/adapters/Caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class CachingAdapter implements Adapter {
}
foundBookmark.url = newBm.url
foundBookmark.title = newBm.title
if (foundBookmark.parentId === newBm.parentId) {
if (String(foundBookmark.parentId) === String(newBm.parentId)) {
return
}
const foundOldFolder = this.bookmarksCache.findFolder(
Expand Down Expand Up @@ -154,12 +154,12 @@ export default class CachingAdapter implements Adapter {
}
order.forEach(item => {
const child = folder.findItem(item.type, item.id)
if (!child || child.parentId !== folder.id) {
if (!child || String(child.parentId) !== String(folder.id)) {
throw new UnknownFolderItemOrderError(id + ':' + JSON.stringify(item))
}
})
folder.children.forEach(child => {
const item = order.find((item) => item.type === child.type && item.id === child.id)
const item = order.find((item) => item.type === child.type && String(item.id) === String(child.id))
if (!item) {
throw new MissingItemOrderError(
id + ':' + child.inspect()
Expand Down
6 changes: 3 additions & 3 deletions src/lib/adapters/NextcloudBookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
}
})
}
return recurseChildren(folderId, children).filter(item => item.id !== this.lockId)
return recurseChildren(folderId, children).filter(item => String(item.id) !== String(this.lockId))
} else {
// We don't have the children endpoint available, so we have to query all bookmarks that exist :(
await this.getBookmarksList()
Expand Down Expand Up @@ -483,7 +483,7 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
)
}
await recurseChildFolders(tree, childFolders, childrenOrder, childBookmarks, layers)
return tree.children.filter(item => item.id !== this.lockId)
return tree.children.filter(item => String(item.id) !== String(this.lockId))
}
}

Expand Down Expand Up @@ -829,7 +829,7 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
)

const newFolder = this.tree.findFolder(newBm.parentId)
if (!newFolder.children.find(item => item.id === newBm.id && item.type === 'bookmark')) {
if (!newFolder.children.find(item => String(item.id) === String(newBm.id) && item.type === 'bookmark')) {
newFolder.children.push(newBm)
}
newBm.id = upstreamId + ';' + newBm.parentId
Expand Down
6 changes: 3 additions & 3 deletions src/lib/browser/BrowserTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class BrowserTree implements IResource {
const recurse = (node, parentId?, rng?) => {
if (
allAccounts.some(
acc => acc.getData().localRoot === node.id && node.id !== this.rootId && !acc.getData().nestedSync
acc => acc.getData().localRoot === node.id && String(node.id) !== String(this.rootId) && !acc.getData().nestedSync
)
) {
// This is the root folder of a different account and the user doesn't want nested sync
Expand Down Expand Up @@ -223,8 +223,8 @@ export default class BrowserTree implements IResource {
if (realTree.children.length !== order.length) {
const untouchedChildren = realTree.children.map((child,i) => [i, child]).filter(([, child]) =>
child.url
? !order.some(item => item.type === ItemType.BOOKMARK && item.id === child.id)
: !order.some(item => item.type === ItemType.FOLDER && item.id === child.id)
? !order.some(item => item.type === ItemType.BOOKMARK && String(item.id) === String(child.id))
: !order.some(item => item.type === ItemType.FOLDER && String(item.id) === String(child.id))
)
try {
Logger.log('Move untouched children back into place', {untouchedChildren: untouchedChildren.map(([i, item]) => [i, item.id])})
Expand Down
10 changes: 5 additions & 5 deletions src/lib/strategies/Default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ export default class SyncProcess {

if (
// Don't create duplicates!
targetPlan.getActions(ActionType.MOVE).find(move => move.payload.id === payload.id) ||
sourceDiff.getActions(ActionType.MOVE).find(move => move.payload.id === payload.id) ||
targetPlan.getActions(ActionType.MOVE).find(move => String(move.payload.id) === String(payload.id)) ||
sourceDiff.getActions(ActionType.MOVE).find(move => String(move.payload.id) === String(payload.id)) ||
// Don't move back into removed territory
targetRemovals.find(remove => Diff.findChain(mappingsSnapshot, allCreateAndMoveActions, sourceTree, action.payload, remove)) ||
sourceRemovals.find(remove => Diff.findChain(mappingsSnapshot, allCreateAndMoveActions, targetTree, action.payload, remove))
Expand Down Expand Up @@ -829,12 +829,12 @@ export default class SyncProcess {
const reconciled = !cacheItem
const changedLocally =
(localHash !== cacheHash) ||
(cacheItem && localItem.parentId !== cacheItem.parentId)
(cacheItem && String(localItem.parentId) !== String(cacheItem.parentId))
const changedUpstream =
(cacheHash !== serverHash) ||
(cacheItem &&
cacheItem.parentId !==
mappingsSnapshot.ServerToLocal.folder[serverItem.parentId])
String(cacheItem.parentId) !==
String(mappingsSnapshot.ServerToLocal.folder[serverItem.parentId]))
return changedLocally || changedUpstream || reconciled
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/strategies/Merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export default class MergeSyncProcess extends Default {
oldItem.parentId = Mappings.mapParentId(mappingsSnapshot, oldItem, action.payload.location)

if (
targetPlan.getActions(ActionType.MOVE).find(move => move.payload.id === payload.id) ||
sourceDiff.getActions(ActionType.MOVE).find(move => move.payload.id === payload.id)
targetPlan.getActions(ActionType.MOVE).find(move => String(move.payload.id) === String(payload.id)) ||
sourceDiff.getActions(ActionType.MOVE).find(move => String(move.payload.id) === String(payload.id))
) {
// Don't create duplicates!
return
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/native/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export default {
},
breadcrumbs() {
const folders = [this.currentFolder]
while (folders[folders.length - 1 ].id !== this.tree.id) {
while (String(folders[folders.length - 1 ].id) !== String(this.tree.id)) {
folders.push(this.findItem(folders[folders.length - 1 ].parentId, this.tree))
}
return folders.reverse()
Expand Down

0 comments on commit 93202b2

Please sign in to comment.