refactor(omnibox): keep favorites tags-safe
- commit
- dd1fd2b30585ba725ab7cb1514118fc3e637cba4
- author
- brice · · 2026-06-28 07:41 UTC
- parent
- 45b8a06
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +44 -9
M internal/ui/component/omnibox.go +14 -9
| @@ -1753,20 +1753,25 @@ func (o *Omnibox) loadFavorites(query string, token uint64) { | |||
| 1753 | 1753 | return | |
| 1754 | 1754 | } | |
| 1755 | 1755 | ||
| 1756 | - | favorites := make([]Favorite, 0, len(results)) | |
| 1757 | - | for i, r := range results { | |
| 1758 | - | favorites = append(favorites, Favorite{ | |
| 1759 | - | ID: int64(r.ID), | |
| 1760 | - | URL: r.URL, | |
| 1761 | - | Title: r.Title, | |
| 1762 | - | Position: i, | |
| 1763 | - | }) | |
| 1764 | - | } | |
| 1756 | + | favorites := favoriteResultsForOmnibox(results) | |
| 1765 | 1757 | ||
| 1766 | 1758 | o.idleAddUpdateFavorites(favorites, query, token) | |
| 1767 | 1759 | }() | |
| 1768 | 1760 | } | |
| 1769 | 1761 | ||
| 1762 | + | func favoriteResultsForOmnibox(results []*entity.Favorite) []Favorite { | |
| 1763 | + | favorites := make([]Favorite, 0, len(results)) | |
| 1764 | + | for i, r := range results { | |
| 1765 | + | favorites = append(favorites, Favorite{ | |
| 1766 | + | ID: int64(r.ID), | |
| 1767 | + | URL: r.URL, | |
| 1768 | + | Title: r.Title, | |
| 1769 | + | Position: i, | |
| 1770 | + | }) | |
| 1771 | + | } | |
| 1772 | + | return favorites | |
| 1773 | + | } | |
| 1774 | + | ||
| 1770 | 1775 | func (o *Omnibox) loadBangSuggestions(query string, token uint64) { | |
| 1771 | 1776 | if o.shortcutsUC == nil { | |
| 1772 | 1777 | return | |
| @@ -1753,20 +1753,25 @@ func (o *Omnibox) loadFavorites(query string, token uint64) { | |||||
| 1753 | return | 1753 | return | ||
| 1754 | } | 1754 | } | ||
| 1755 | 1755 | ||||
| 1756 | - | favorites := make([]Favorite, 0, len(results)) | 1756 | + | favorites := favoriteResultsForOmnibox(results) |
| 1757 | - | for i, r := range results { | |||
| 1758 | - | favorites = append(favorites, Favorite{ | |||
| 1759 | - | ID: int64(r.ID), | |||
| 1760 | - | URL: r.URL, | |||
| 1761 | - | Title: r.Title, | |||
| 1762 | - | Position: i, | |||
| 1763 | - | }) | |||
| 1764 | - | } | |||
| 1765 | 1757 | ||||
| 1766 | o.idleAddUpdateFavorites(favorites, query, token) | 1758 | o.idleAddUpdateFavorites(favorites, query, token) | ||
| 1767 | }() | 1759 | }() | ||
| 1768 | } | 1760 | } | ||
| 1769 | 1761 | ||||
| 1762 | + | func favoriteResultsForOmnibox(results []*entity.Favorite) []Favorite { | |||
| 1763 | + | favorites := make([]Favorite, 0, len(results)) | |||
| 1764 | + | for i, r := range results { | |||
| 1765 | + | favorites = append(favorites, Favorite{ | |||
| 1766 | + | ID: int64(r.ID), | |||
| 1767 | + | URL: r.URL, | |||
| 1768 | + | Title: r.Title, | |||
| 1769 | + | Position: i, | |||
| 1770 | + | }) | |||
| 1771 | + | } | |||
| 1772 | + | return favorites | |||
| 1773 | + | } | |||
| 1774 | + | ||||
| 1770 | func (o *Omnibox) loadBangSuggestions(query string, token uint64) { | 1775 | func (o *Omnibox) loadBangSuggestions(query string, token uint64) { | ||
| 1771 | if o.shortcutsUC == nil { | 1776 | if o.shortcutsUC == nil { | ||
| 1772 | return | 1777 | return | ||
A internal/ui/component/omnibox_favorite_search_test.go +30 -0
| @@ -0,0 +1,30 @@ | |||
| 1 | + | package component | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "testing" | |
| 5 | + | ||
| 6 | + | "github.com/bnema/dumber/internal/domain/entity" | |
| 7 | + | "github.com/stretchr/testify/assert" | |
| 8 | + | ) | |
| 9 | + | ||
| 10 | + | func TestOmniboxFavoriteSearchResultsAllowTagsPresent(t *testing.T) { | |
| 11 | + | results := []*entity.Favorite{ | |
| 12 | + | { | |
| 13 | + | ID: 1, | |
| 14 | + | URL: "https://example.com/docs", | |
| 15 | + | Title: "Docs", | |
| 16 | + | Tags: []entity.Tag{{ID: 7, Name: "Go"}}, | |
| 17 | + | }, | |
| 18 | + | } | |
| 19 | + | ||
| 20 | + | favorites := favoriteResultsForOmnibox(results) | |
| 21 | + | ||
| 22 | + | assert.Equal(t, []Favorite{ | |
| 23 | + | { | |
| 24 | + | ID: 1, | |
| 25 | + | URL: "https://example.com/docs", | |
| 26 | + | Title: "Docs", | |
| 27 | + | Position: 0, | |
| 28 | + | }, | |
| 29 | + | }, favorites) | |
| 30 | + | } | |
| @@ -0,0 +1,30 @@ | |||||
| 1 | + | package component | |||
| 2 | + | ||||
| 3 | + | import ( | |||
| 4 | + | "testing" | |||
| 5 | + | ||||
| 6 | + | "github.com/bnema/dumber/internal/domain/entity" | |||
| 7 | + | "github.com/stretchr/testify/assert" | |||
| 8 | + | ) | |||
| 9 | + | ||||
| 10 | + | func TestOmniboxFavoriteSearchResultsAllowTagsPresent(t *testing.T) { | |||
| 11 | + | results := []*entity.Favorite{ | |||
| 12 | + | { | |||
| 13 | + | ID: 1, | |||
| 14 | + | URL: "https://example.com/docs", | |||
| 15 | + | Title: "Docs", | |||
| 16 | + | Tags: []entity.Tag{{ID: 7, Name: "Go"}}, | |||
| 17 | + | }, | |||
| 18 | + | } | |||
| 19 | + | ||||
| 20 | + | favorites := favoriteResultsForOmnibox(results) | |||
| 21 | + | ||||
| 22 | + | assert.Equal(t, []Favorite{ | |||
| 23 | + | { | |||
| 24 | + | ID: 1, | |||
| 25 | + | URL: "https://example.com/docs", | |||
| 26 | + | Title: "Docs", | |||
| 27 | + | Position: 0, | |||
| 28 | + | }, | |||
| 29 | + | }, favorites) | |||
| 30 | + | } | |||