Fix query-by-match for multi-colon values

Change-Id: Idc16bb535f4ec07d5aaee9f9d241d9eee6c6bf6e
diff --git a/dev/js/spec/queryCreatorSpec.js b/dev/js/spec/queryCreatorSpec.js
index 780a7bf..c3e041d 100644
--- a/dev/js/spec/queryCreatorSpec.js
+++ b/dev/js/spec/queryCreatorSpec.js
@@ -88,6 +88,7 @@
     "            <div>gender:masc</div>" +
     "            <div>number:sg</div>" +
     "            <div>morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'</div>" +
+    "            <div>morphemes:ZERO::NOM</div>" +
     "          </td>" +
     "          <td>ADJA</td>" +
     "          <td></td>" +
@@ -505,8 +506,8 @@
     });
 
     it('should create and-groups for key-value terms', function () {
-      var matchTable = matchTableComplexFactory();
-      var qc = qcClass.create(matchTable);
+      const matchTable = matchTableComplexFactory();
+      const qc = qcClass.create(matchTable);
 
       // Nothing to show
       expect(qc.toString()).toEqual("");
@@ -515,7 +516,7 @@
       expect(qc.shown()).toBe(false);
       expect(qc.element().className).toEqual("query fragment");
 
-      var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
+      let cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
       expect(cell.innerString()).toEqual("lebende und sterbende");
       expect(cell.classList.contains("chosen")).toBe(false);
       cell.click();
@@ -537,7 +538,6 @@
       cell.click();
       expect(cell.classList.contains("chosen")).toBe(true);
       expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom]");
-      var cell = cell;
 
       cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)");
       expect(cell.innerString()).toEqual('number:sg');
@@ -545,7 +545,7 @@
       cell.click();
       expect(cell.classList.contains("chosen")).toBe(true);
       expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom & corenlp/p=number:sg]");
-      var cell2 = cell;
+      let cell2 = cell;
 
       cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(2)");
       expect(cell.innerString()).toEqual('gender:mascgender:fem');
@@ -553,7 +553,7 @@
       cell.click();
       expect(cell.classList.contains("chosen")).toBe(true);
       expect(qc.toString()).toEqual("[orth='lebende und sterbende'][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]");
-      var cell3 = cell;
+      let cell3 = cell;
 
       // Remove cell again
       cell = cell2;
@@ -616,7 +616,7 @@
 
       // TODO:
       // This does not respect keys vs values at the moment, but neither does Koral
-      var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(4)");
+      let cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(4)");
       expect(cell.innerString()).toEqual("morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'");
       expect(cell.classList.contains("chosen")).toBe(false);
       cell.click();
@@ -643,6 +643,16 @@
       cell.click()
       expect(cell.classList.contains("chosen")).toBe(false);
       expect(qc.toString()).toEqual("");
+
+      cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(5)");
+      expect(cell.innerString()).toEqual("morphemes:ZERO::NOM");
+      expect(cell.classList.contains("chosen")).toBe(false);
+      cell.click();
+      expect(cell.classList.contains("chosen")).toBeTruthy();
+      expect(qc.toString()).toEqual("[opennlp/p='morphemes:ZERO::NOM']");
+      cell.click()
+      expect(cell.classList.contains("chosen")).toBe(false);
+      expect(qc.toString()).toEqual("");
     });
 
     it('should respect marked elements', function () {
diff --git a/dev/js/src/match/querycreator.js b/dev/js/src/match/querycreator.js
index 09d91b8..f4b819f 100644
--- a/dev/js/src/match/querycreator.js
+++ b/dev/js/src/match/querycreator.js
@@ -20,10 +20,10 @@
   const loc = KorAP.Locale;
   loc.NEW_QUERY = loc.NEW_QUERY || 'New Query';
 
-  const esc = RegExp("[ \.\'\\\\\|\&]");
+  const esc = RegExp("^(?:[^ \:\.\'\\\\\|\&]+:)?[^ \:\.\'\\\\\|\&]+$");
   
   function _getKeyValue (keyValue) {
-    if (keyValue.match(esc) != null) {
+    if (keyValue.match(esc) === null) {
       return "'" + keyValue.replace(/\\/g, "\\\\").replace(/'/g, "\\'") + "'";
     };
     return keyValue;