diff --git a/toolkit/components/places/Bookmarks.jsm b/toolkit/components/places/Bookmarks.jsm index db03fb309273..75e2a0d6de1c 100644 --- a/toolkit/components/places/Bookmarks.jsm +++ b/toolkit/components/places/Bookmarks.jsm @@ -1228,7 +1228,12 @@ const VALIDATORS = Object.freeze({ return new URL(v.spec); return v; }, - keyword: simpleValidateFunc(v => typeof(v) == "string" && /^\S*$/.test(v)), + keyword: v => { + simpleValidateFunc(val => typeof(val) == "string" && /^\S*$/.test(val)) + .call(this, v); + // Keywords are handled as case-insensitive. + return v.toLowerCase(); + } }); /** diff --git a/toolkit/components/places/tests/bookmarks/test_bookmarks_fetch.js b/toolkit/components/places/tests/bookmarks/test_bookmarks_fetch.js index 039bdfb662c0..ce8bfdb7ffb9 100644 --- a/toolkit/components/places/tests/bookmarks/test_bookmarks_fetch.js +++ b/toolkit/components/places/tests/bookmarks/test_bookmarks_fetch.js @@ -329,6 +329,7 @@ add_task(function* fetch_bykeyword() { Assert.equal(bm2.url.href, "http://bykeyword1.com/"); Assert.equal(bm2.keyword, "bykeyword"); + // Add a second url using the same keyword. let bm3 = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid, type: PlacesUtils.bookmarks.TYPE_BOOKMARK, url: "http://bykeyword2.com/", @@ -352,6 +353,16 @@ add_task(function* fetch_bykeyword() { Assert.equal(gAccumulator.results.length, 2); gAccumulator.results.forEach(checkBookmarkObject); Assert.deepEqual(gAccumulator.results[0], bm5); + + // Check fetching by keyword is case-insensitive. + let bm6 = yield PlacesUtils.bookmarks.fetch({ keyword: "ByKeYwOrD" }, + gAccumulator.callback); + checkBookmarkObject(bm6); + // Cannot use deepEqual cause lastModified changed. + Assert.equal(bm1.guid, bm6.guid); + Assert.equal(gAccumulator.results.length, 2); + gAccumulator.results.forEach(checkBookmarkObject); + Assert.deepEqual(gAccumulator.results[0], bm6); }); function run_test() { diff --git a/toolkit/components/places/tests/bookmarks/test_bookmarks_insert.js b/toolkit/components/places/tests/bookmarks/test_bookmarks_insert.js index d477aa8e117d..de728aea7d98 100644 --- a/toolkit/components/places/tests/bookmarks/test_bookmarks_insert.js +++ b/toolkit/components/places/tests/bookmarks/test_bookmarks_insert.js @@ -243,10 +243,11 @@ add_task(function* create_bookmark() { let parent = yield PlacesUtils.bookmarks.fetch({ guid: bm.parentGuid }); Assert.deepEqual(parent.lastModified, bm.dateAdded); + // While here, also check keywords are case-insensitive. bm = yield PlacesUtils.bookmarks.insert({ parentGuid: parentGuid, type: PlacesUtils.bookmarks.TYPE_BOOKMARK, url: NetUtil.newURI("http://example.com/"), - keyword: "test" }); + keyword: "tEsT" }); checkBookmarkObject(bm); Assert.equal(bm.parentGuid, parentGuid); Assert.equal(bm.index, 1); diff --git a/toolkit/components/places/tests/bookmarks/test_bookmarks_notifications.js b/toolkit/components/places/tests/bookmarks/test_bookmarks_notifications.js index 9491a4d39037..cff76962b411 100644 --- a/toolkit/components/places/tests/bookmarks/test_bookmarks_notifications.js +++ b/toolkit/components/places/tests/bookmarks/test_bookmarks_notifications.js @@ -75,9 +75,11 @@ add_task(function* insert_bookmark_keyword_notification() { let bm = yield PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK, parentGuid: PlacesUtils.bookmarks.unfiledGuid, url: new URL("http://example.com/"), - keyword: "kw" }); + keyword: "Kw" }); let itemId = yield PlacesUtils.promiseItemId(bm.guid); let parentId = yield PlacesUtils.promiseItemId(bm.parentGuid); + // Keywords are case-insensitive. + Assert.equal(bm.keyword, "kw"); observer.check([ { name: "onItemAdded", arguments: [ itemId, parentId, bm.index, bm.type, bm.url, null, bm.dateAdded, @@ -173,7 +175,9 @@ add_task(function* update_bookmark_keyword() { parentGuid: PlacesUtils.bookmarks.unfiledGuid, url: new URL("http://keyword.example.com/") }); let observer = expectNotifications(); - bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid, keyword: "kw" }); + bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid, keyword: "kW" }); + // Keywords are case-insensitive. + Assert.equal(bm.keyword, "kw"); let itemId = yield PlacesUtils.promiseItemId(bm.guid); let parentId = yield PlacesUtils.promiseItemId(bm.parentGuid); diff --git a/toolkit/components/places/tests/bookmarks/test_bookmarks_remove.js b/toolkit/components/places/tests/bookmarks/test_bookmarks_remove.js index f4c986ec1035..54048df4e4f6 100644 --- a/toolkit/components/places/tests/bookmarks/test_bookmarks_remove.js +++ b/toolkit/components/places/tests/bookmarks/test_bookmarks_remove.js @@ -90,13 +90,14 @@ add_task(function* remove_bookmark_orphans() { type: PlacesUtils.bookmarks.TYPE_BOOKMARK, url: "http://example.com/", title: "a bookmark", - keyword: "test"}); + keyword: "tEsT"}); checkBookmarkObject(bm1); PlacesUtils.annotations.setItemAnnotation((yield PlacesUtils.promiseItemId(bm1.guid)), "testanno", "testvalue", 0, 0); let bm2 = yield PlacesUtils.bookmarks.remove(bm1.guid); checkBookmarkObject(bm2); + // Keywords are case-insensitive. Assert.equal(bm2.keyword, "test"); // Check there are no orphan keywords or annotations. diff --git a/toolkit/components/places/tests/bookmarks/test_bookmarks_update.js b/toolkit/components/places/tests/bookmarks/test_bookmarks_update.js index d74dbc79cc41..a6af9072f939 100644 --- a/toolkit/components/places/tests/bookmarks/test_bookmarks_update.js +++ b/toolkit/components/places/tests/bookmarks/test_bookmarks_update.js @@ -248,12 +248,14 @@ add_task(function* update_keyword() { let lastModified = bm.lastModified; bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid, - keyword: "kw2" }); + keyword: "KW2" }); checkBookmarkObject(bm); Assert.ok(bm.lastModified >= lastModified); + // Keywords are case-insensitive. Assert.equal(bm.keyword, "kw2"); bm = yield PlacesUtils.bookmarks.fetch(bm.guid); + // Keywords are case-insensitive. Assert.equal(bm.keyword, "kw2"); lastModified = bm.lastModified;