changeset f73ea3aa0f50 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=f73ea3aa0f50
description:
        Detect all wild cards and escaped wild cards in likify

        issue10020
        review320611002
diffstat:

 src/common.js |   9 ++++++---
 tests/sao.js  |  18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diffs (50 lines):

diff -r 9d89c0c569a8 -r f73ea3aa0f50 src/common.js
--- a/src/common.js     Fri Jan 29 00:04:29 2021 +0100
+++ b/src/common.js     Wed Feb 03 19:30:13 2021 +0100
@@ -1804,12 +1804,15 @@
             }.bind(this));
             return result;
         },
-        likify: function(value) {
+        likify: function(value, escape) {
+            escape = escape || '\\';
             if (!value) {
                 return '%';
             }
-            var escaped = value.replace('%%', '__');
-            if (escaped.contains('%')) {
+            var escaped = value
+                .replace(escape + '%', '')
+                .replace(escape + '_', '');
+            if (escaped.contains('%') || escaped.contains('_')) {
                 return value;
             } else {
                 return '%' + value + '%';
diff -r 9d89c0c569a8 -r f73ea3aa0f50 tests/sao.js
--- a/tests/sao.js      Fri Jan 29 00:04:29 2021 +0100
+++ b/tests/sao.js      Wed Feb 03 19:30:13 2021 +0100
@@ -1531,6 +1531,24 @@
         });
     });
 
+    QUnit.test('DomainParser.likify', function() {
+        var parser = new Sao.common.DomainParser();
+
+        [
+            ['', '%'],
+            ['foo', '%foo%'],
+            ['foo%', 'foo%'],
+            ['foo_bar', 'foo_bar'],
+            ['foo\\%', '%foo\\%%'],
+            ['foo\\_bar', '%foo\\_bar%'],
+        ].forEach(function(test) {
+            var value = test[0];
+            var result = test[1];
+            QUnit.ok(Sao.common.compare(parser.likify(value), result),
+                'likify(' + JSON.stringify(value) + ')');
+        });
+    });
+
     QUnit.test('DomainParser.quote', function() {
         var parser = new Sao.common.DomainParser();
 

Reply via email to