storage/test/unit/test_like_escape.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 const LATIN1_AE = "\xc6";
     6 const LATIN1_ae = "\xe6"; 
     8 function setup()
     9 {
    10   getOpenedDatabase().createTable("t1", "x TEXT");
    12   var stmt = createStatement("INSERT INTO t1 (x) VALUES ('foo/bar_baz%20cheese')");
    13   stmt.execute();
    14   stmt.finalize();
    16   stmt = createStatement("INSERT INTO t1 (x) VALUES (?1)");
    17   // insert LATIN_ae, but search on LATIN_AE
    18   stmt.bindByIndex(0, "foo%20" + LATIN1_ae + "/_bar");
    19   stmt.execute();
    20   stmt.finalize();
    21 }
    23 function test_escape_for_like_ascii()
    24 {
    25   var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?1 ESCAPE '/'");
    26   var paramForLike = stmt.escapeStringForLIKE("oo/bar_baz%20chees", '/');
    27   // verify that we escaped / _ and %
    28   do_check_eq(paramForLike, "oo//bar/_baz/%20chees");
    29   // prepend and append with % for "contains"
    30   stmt.bindByIndex(0, "%" + paramForLike + "%"); 
    31   stmt.executeStep();
    32   do_check_eq("foo/bar_baz%20cheese", stmt.getString(0));
    33   stmt.finalize();
    34 }
    36 function test_escape_for_like_non_ascii()
    37 {
    38   var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?1 ESCAPE '/'");
    39   var paramForLike = stmt.escapeStringForLIKE("oo%20" + LATIN1_AE + "/_ba", '/');
    40   // verify that we escaped / _ and %
    41   do_check_eq(paramForLike, "oo/%20" + LATIN1_AE + "///_ba");
    42   // prepend and append with % for "contains"
    43   stmt.bindByIndex(0, "%" + paramForLike + "%");
    44   stmt.executeStep();
    45   do_check_eq("foo%20" + LATIN1_ae + "/_bar", stmt.getString(0));
    46   stmt.finalize();
    47 }
    49 var tests = [test_escape_for_like_ascii, test_escape_for_like_non_ascii];
    51 function run_test()
    52 {
    53   setup();
    55   for (var i = 0; i < tests.length; i++)
    56     tests[i]();
    58   cleanup();
    59 }

mercurial