michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const LATIN1_AE = "\xc6"; michael@0: const LATIN1_ae = "\xe6"; michael@0: michael@0: function setup() michael@0: { michael@0: getOpenedDatabase().createTable("t1", "x TEXT"); michael@0: michael@0: var stmt = createStatement("INSERT INTO t1 (x) VALUES ('foo/bar_baz%20cheese')"); michael@0: stmt.execute(); michael@0: stmt.finalize(); michael@0: michael@0: stmt = createStatement("INSERT INTO t1 (x) VALUES (?1)"); michael@0: // insert LATIN_ae, but search on LATIN_AE michael@0: stmt.bindByIndex(0, "foo%20" + LATIN1_ae + "/_bar"); michael@0: stmt.execute(); michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: function test_escape_for_like_ascii() michael@0: { michael@0: var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?1 ESCAPE '/'"); michael@0: var paramForLike = stmt.escapeStringForLIKE("oo/bar_baz%20chees", '/'); michael@0: // verify that we escaped / _ and % michael@0: do_check_eq(paramForLike, "oo//bar/_baz/%20chees"); michael@0: // prepend and append with % for "contains" michael@0: stmt.bindByIndex(0, "%" + paramForLike + "%"); michael@0: stmt.executeStep(); michael@0: do_check_eq("foo/bar_baz%20cheese", stmt.getString(0)); michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: function test_escape_for_like_non_ascii() michael@0: { michael@0: var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?1 ESCAPE '/'"); michael@0: var paramForLike = stmt.escapeStringForLIKE("oo%20" + LATIN1_AE + "/_ba", '/'); michael@0: // verify that we escaped / _ and % michael@0: do_check_eq(paramForLike, "oo/%20" + LATIN1_AE + "///_ba"); michael@0: // prepend and append with % for "contains" michael@0: stmt.bindByIndex(0, "%" + paramForLike + "%"); michael@0: stmt.executeStep(); michael@0: do_check_eq("foo%20" + LATIN1_ae + "/_bar", stmt.getString(0)); michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: var tests = [test_escape_for_like_ascii, test_escape_for_like_non_ascii]; michael@0: michael@0: function run_test() michael@0: { michael@0: setup(); michael@0: michael@0: for (var i = 0; i < tests.length; i++) michael@0: tests[i](); michael@0: michael@0: cleanup(); michael@0: }