diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-06-30 08:20:38 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-06-30 08:20:38 +0300 |
commit | 73a721fc93c3be7b13361dea41d4431ad14a3fdd (patch) | |
tree | e6de1687d1932509789e21ed4232fe2c6def32ad /src/bookmarks.c | |
parent | 42d461f32eb77a83c0f9d7b4fb202de72c64a97f (diff) |
Canonical URIs
Internally, all URIs should be converted to a canonical form so that they can be compared against each other.
The canonical form is an IRI with spaces and reserved characters percent-encoded.
Diffstat (limited to 'src/bookmarks.c')
-rw-r--r-- | src/bookmarks.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c index 1f887c98..65cc7982 100644 --- a/src/bookmarks.c +++ b/src/bookmarks.c | |||
@@ -158,6 +158,7 @@ void load_Bookmarks(iBookmarks *d, const char *dirPath) { | |||
158 | appendChar_String(&bm->url, '/'); | 158 | appendChar_String(&bm->url, '/'); |
159 | } | 159 | } |
160 | stripDefaultUrlPort_String(&bm->url); | 160 | stripDefaultUrlPort_String(&bm->url); |
161 | set_String(&bm->url, canonicalUrl_String(&bm->url)); | ||
161 | } | 162 | } |
162 | nextSplit_Rangecc(src, "\n", &line); | 163 | nextSplit_Rangecc(src, "\n", &line); |
163 | setRange_String(&bm->title, line); | 164 | setRange_String(&bm->title, line); |
@@ -201,7 +202,7 @@ uint32_t add_Bookmarks(iBookmarks *d, const iString *url, const iString *title, | |||
201 | iChar icon) { | 202 | iChar icon) { |
202 | lock_Mutex(d->mtx); | 203 | lock_Mutex(d->mtx); |
203 | iBookmark *bm = new_Bookmark(); | 204 | iBookmark *bm = new_Bookmark(); |
204 | set_String(&bm->url, url); | 205 | set_String(&bm->url, canonicalUrl_String(url)); |
205 | set_String(&bm->title, title); | 206 | set_String(&bm->title, title); |
206 | if (tags) { | 207 | if (tags) { |
207 | set_String(&bm->tags, tags); | 208 | set_String(&bm->tags, tags); |
@@ -298,6 +299,7 @@ static iBool matchUrl_(void *url, const iBookmark *bm) { | |||
298 | 299 | ||
299 | uint32_t findUrl_Bookmarks(const iBookmarks *d, const iString *url) { | 300 | uint32_t findUrl_Bookmarks(const iBookmarks *d, const iString *url) { |
300 | /* TODO: O(n), boo */ | 301 | /* TODO: O(n), boo */ |
302 | url = canonicalUrl_String(url); | ||
301 | const iPtrArray *found = list_Bookmarks(d, NULL, matchUrl_, (void *) url); | 303 | const iPtrArray *found = list_Bookmarks(d, NULL, matchUrl_, (void *) url); |
302 | if (isEmpty_PtrArray(found)) return 0; | 304 | if (isEmpty_PtrArray(found)) return 0; |
303 | return id_Bookmark(constFront_PtrArray(found)); | 305 | return id_Bookmark(constFront_PtrArray(found)); |
@@ -448,7 +450,7 @@ void requestFinished_Bookmarks(iBookmarks *d, iGmRequest *req) { | |||
448 | const iRangecc url = capturedRange_RegExpMatch(&m, 1); | 450 | const iRangecc url = capturedRange_RegExpMatch(&m, 1); |
449 | const iRangecc title = capturedRange_RegExpMatch(&m, 3); | 451 | const iRangecc title = capturedRange_RegExpMatch(&m, 3); |
450 | iString * urlStr = newRange_String(url); | 452 | iString * urlStr = newRange_String(url); |
451 | const iString *absUrl = absoluteUrl_String(url_GmRequest(req), urlStr); | 453 | const iString *absUrl = canonicalUrl_String(absoluteUrl_String(url_GmRequest(req), urlStr)); |
452 | if (!findUrl_Bookmarks(d, absUrl)) { | 454 | if (!findUrl_Bookmarks(d, absUrl)) { |
453 | iString *titleStr = newRange_String(title); | 455 | iString *titleStr = newRange_String(title); |
454 | if (isEmpty_String(titleStr)) { | 456 | if (isEmpty_String(titleStr)) { |