Skip to content

Commit 496f4e2

Browse files
committed
fix(Tree#search): Harden search
see #1880 Signed-off-by: Marcel Klehr <[email protected]>
1 parent f5f3b0c commit 496f4e2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/ui/views/native/Tree.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ export default {
506506
return []
507507
}
508508
let items
509-
if (this.searchQuery && this.searchQuery.length >= 2) {
509+
if (this.searchQuery && this.searchQuery.trim().length >= 2) {
510510
return this.search(this.searchQuery.toLowerCase().trim(), this.currentFolder)
511511
} else {
512512
items = this.currentFolder.children
@@ -515,7 +515,11 @@ export default {
515515
return sortBy(items, [(item) => {
516516
if (this.sortBy === 'url') {
517517
if (item.url) {
518-
return new URL(item.url).hostname
518+
try {
519+
return new URL(item.url).hostname
520+
} catch (e) {
521+
return item.url.toLowerCase()
522+
}
519523
} else {
520524
return '0000000' + item.title.toLowerCase() // folders to the top
521525
}
@@ -527,7 +531,7 @@ export default {
527531
}
528532
},
529533
otherSearchItems() {
530-
if (!this.currentFolder && (!this.searchQuery || this.searchQuery.length < 2)) {
534+
if (!this.currentFolder && (!this.searchQuery || this.searchQuery.trim().length < 2)) {
531535
return []
532536
}
533537
return this.search(this.searchQuery.toLowerCase().trim(), this.tree).filter(item => !this.items.includes(item))

0 commit comments

Comments
 (0)