summaryrefslogtreecommitdiffstats
path: root/storage/test/unit/test_like_escape.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /storage/test/unit/test_like_escape.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'storage/test/unit/test_like_escape.js')
-rw-r--r--storage/test/unit/test_like_escape.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/storage/test/unit/test_like_escape.js b/storage/test/unit/test_like_escape.js
new file mode 100644
index 000000000..414f6237c
--- /dev/null
+++ b/storage/test/unit/test_like_escape.js
@@ -0,0 +1,60 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const LATIN1_AE = "\xc6";
+const LATIN1_ae = "\xe6";
+
+function setup()
+{
+ getOpenedDatabase().createTable("t1", "x TEXT");
+
+ var stmt = createStatement("INSERT INTO t1 (x) VALUES ('foo/bar_baz%20cheese')");
+ stmt.execute();
+ stmt.finalize();
+
+ stmt = createStatement("INSERT INTO t1 (x) VALUES (?1)");
+ // insert LATIN_ae, but search on LATIN_AE
+ stmt.bindByIndex(0, "foo%20" + LATIN1_ae + "/_bar");
+ stmt.execute();
+ stmt.finalize();
+}
+
+function test_escape_for_like_ascii()
+{
+ var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?1 ESCAPE '/'");
+ var paramForLike = stmt.escapeStringForLIKE("oo/bar_baz%20chees", '/');
+ // verify that we escaped / _ and %
+ do_check_eq(paramForLike, "oo//bar/_baz/%20chees");
+ // prepend and append with % for "contains"
+ stmt.bindByIndex(0, "%" + paramForLike + "%");
+ stmt.executeStep();
+ do_check_eq("foo/bar_baz%20cheese", stmt.getString(0));
+ stmt.finalize();
+}
+
+function test_escape_for_like_non_ascii()
+{
+ var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?1 ESCAPE '/'");
+ var paramForLike = stmt.escapeStringForLIKE("oo%20" + LATIN1_AE + "/_ba", '/');
+ // verify that we escaped / _ and %
+ do_check_eq(paramForLike, "oo/%20" + LATIN1_AE + "///_ba");
+ // prepend and append with % for "contains"
+ stmt.bindByIndex(0, "%" + paramForLike + "%");
+ stmt.executeStep();
+ do_check_eq("foo%20" + LATIN1_ae + "/_bar", stmt.getString(0));
+ stmt.finalize();
+}
+
+var tests = [test_escape_for_like_ascii, test_escape_for_like_non_ascii];
+
+function run_test()
+{
+ setup();
+
+ for (var i = 0; i < tests.length; i++) {
+ tests[i]();
+ }
+
+ cleanup();
+}