Bug 1498584 - Unable to delete urls containing backslashes from history. r=Standard8
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 19 Oct 2018 13:19:24 +0000
changeset 497944 36e622253bc438b14e6356138492f445c9360eab
parent 497943 8b7834399818e8a4d73d0350e493114241531a4a
child 497945 b4934bce3c1eaf5e25ccda5418b174c620dac845
push id10016
push userrgurzau@mozilla.com
push dateMon, 22 Oct 2018 13:58:55 +0000
treeherdermozilla-beta@848cf6354160 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1498584
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1498584 - Unable to delete urls containing backslashes from history. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D9097
toolkit/components/places/History.jsm
toolkit/components/places/tests/history/test_remove.js
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -781,18 +781,18 @@ function convertForUpdatePlaces(pageInfo
   }
   return info;
 }
 
 /**
  * Convert a list of strings or numbers to its SQL
  * representation as a string.
  */
-function sqlList(list) {
-  return list.map(JSON.stringify).join();
+function sqlList(list, prefix = "", suffix = "") {
+  return list.map(str => `${prefix}"${str}"${suffix}`).join();
 }
 
 /**
  * Invalidate and recompute the frecency of a list of pages,
  * informing frecency observers.
  *
  * @param db: (Sqlite connection)
  * @param idList: (Array)
@@ -1347,17 +1347,17 @@ var removeByFilter = async function(db, 
 
 // Inner implementation of History.remove.
 var remove = async function(db, {guids, urls}, onResult = null) {
   // 1. Find out what needs to be removed
   let query =
     `SELECT id, url, url_hash, guid, foreign_count, title, frecency
      FROM moz_places
      WHERE guid IN (${ sqlList(guids) })
-        OR (url_hash IN (${ urls.map(u => "hash(" + JSON.stringify(u) + ")").join(",") })
+        OR (url_hash IN (${ sqlList(urls, "hash(", ")") })
             AND url IN (${ sqlList(urls) }))
     `;
 
   let onResultData = onResult ? [] : null;
   let pages = [];
   let hasPagesToRemove = false;
   await db.execute(query, null, function(row) {
     let hasForeign = row.getResultByName("foreign_count") != 0;
--- a/toolkit/components/places/tests/history/test_remove.js
+++ b/toolkit/components/places/tests/history/test_remove.js
@@ -228,8 +228,18 @@ add_task(async function test_orphans() {
 
   let db = await PlacesUtils.promiseDBConnection();
   let rows = await db.execute(`SELECT (SELECT count(*) FROM moz_annos) +
                                       (SELECT count(*) FROM moz_icons) +
                                       (SELECT count(*) FROM moz_pages_w_icons) +
                                       (SELECT count(*) FROM moz_icons_to_pages) AS count`);
   Assert.equal(rows[0].getResultByName("count"), 0, "Should not find orphans");
 });
+
+add_task(async function test_remove_backslash() {
+  // Backslash is an escape char in Sqlite, we must take care of that when
+  // removing a url containing a backslash.
+  const url = "https://www.mozilla.org/?test=\u005C";
+  await PlacesTestUtils.addVisits(url);
+  Assert.ok(await PlacesUtils.history.remove(url), "A page should be removed");
+  Assert.deepEqual(await PlacesUtils.history.fetch(url), null,
+                   "The page should not be found");
+});