Fix escaping of regular expressions in VC builder

Change-Id: I172c83fcb7ebb0943b23106891c57aeadca0a1f8
diff --git a/dev/js/spec/vcSpec.js b/dev/js/spec/vcSpec.js
index 3159101..24b24a7 100644
--- a/dev/js/spec/vcSpec.js
+++ b/dev/js/spec/vcSpec.js
@@ -323,15 +323,20 @@
       expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
 
       doc = regexFactory.create({
-	match: "match:ne"
+	      match: "match:ne"
       });
       expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
 
+      doc = regexFactory.create({
+	      value: "WPD/AAA/00001"
+      });
+      expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
+
       doc = dateFactory.create();
       expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
 
       doc = dateFactory.create({
-	value : "2014"
+	      value : "2014"
       });
       expect(doc.toQuery()).toEqual('pubDate in 2014');
     });
diff --git a/dev/js/src/util.js b/dev/js/src/util.js
index 00a2bd5..d803a9d 100644
--- a/dev/js/src/util.js
+++ b/dev/js/src/util.js
@@ -14,6 +14,11 @@
   return this.replace(_quoteRE, '\\$1');
 };
 
+var _escapeRE = new RegExp("([\/\\\\])", 'g');
+String.prototype.escapeRegex = function () {
+  return this.replace(_escapeRE, '\\$1');
+};
+
 // Add toggleClass method similar to jquery
 HTMLElement.prototype.toggleClass = function (c1, c2) {
   var cl = this.classList;
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index b56ba53..6a44fa8 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -567,7 +567,7 @@
         return string + this.value();
         break;
       case "regex":
-        return string + '/' + this.value() + '/';
+        return string + '/' + this.value().escapeRegex() + '/';
         break;
       case "string":
         return string + '"' + this.value().quote() + '"';
diff --git a/dev/js/src/vc/jsonld.js b/dev/js/src/vc/jsonld.js
index 324e7db..846d55c 100644
--- a/dev/js/src/vc/jsonld.js
+++ b/dev/js/src/vc/jsonld.js
@@ -15,21 +15,21 @@
      */
     upgradeTo : function (props) {
       for (var prop in props) {
-	this[prop] = props[prop];
+	      this[prop] = props[prop];
       };
       return this;
     },
     
     ldType : function (type) {
       if (arguments.length === 1)
-	this._ldType = type;
+	      this._ldType = type;
       return this._ldType;
     },
     
     parent : function (obj) {
       if (arguments.length === 1) {
-	this._parent = obj;
-	this.__changed = true;
+	      this._parent = obj;
+	      this.__changed = true;
       };
       return this._parent;
     },
@@ -39,19 +39,19 @@
     // I'm paranoid!
     destroy : function () {
       if (this._ops != undefined) {
-	this._ops._parent = undefined;
-	if (this._ops._element !== undefined)
-	  this._ops._element.refTo = undefined;
-	this._ops = undefined;
+	      this._ops._parent = undefined;
+	      if (this._ops._element !== undefined)
+	        this._ops._element.refTo = undefined;
+	      this._ops = undefined;
       };
       if (this._element !== undefined)
-	this._element = undefined;
+	      this._element = undefined;
       
       // In case of a group, destroy all operands
       if (this._operands !== undefined) {
-	for (var i = 0; i < this._operands.length; i++)
-	  this.getOperand(i).destroy();
-	this._operands = [];
+	      for (var i = 0; i < this._operands.length; i++)
+	        this.getOperand(i).destroy();
+	      this._operands = [];
       };
     },
     
@@ -61,11 +61,11 @@
       
       var group = require('vc/docgroup').create(parent);
       if (arguments.length === 1)
-	group.operation(op);
+	      group.operation(op);
       else
-	group.operation(
-	  this.operation() === 'and' ? 'or' : 'and'
-	);
+	      group.operation(
+	        this.operation() === 'and' ? 'or' : 'and'
+	      );
       group.append(this);
       this.parent(group);
       group.append();
@@ -77,9 +77,9 @@
     // Be aware! This may be cyclic
     operators : function (and, or, del) {
       if (arguments === 0)
-	return this._ops;
+	      return this._ops;
       this._ops = operatorsClass.create(
-	and, or, del
+	      and, or, del
       );
       this._ops.parent(this);
       return this._ops;
@@ -87,8 +87,8 @@
 
     toJson : function () {
       return {
-	// Unspecified object
-	"@type" : "koral:" + this.ldType()
+	      // Unspecified object
+	      "@type" : "koral:" + this.ldType()
       };
     },
 
diff --git a/dev/js/src/vc/stringval.js b/dev/js/src/vc/stringval.js
index c7a5d67..595057a 100644
--- a/dev/js/src/vc/stringval.js
+++ b/dev/js/src/vc/stringval.js
@@ -36,10 +36,10 @@
   regex : function (bool) {
     if (arguments.length === 1) {
       if (bool) {
-	this._regex = true;
+	      this._regex = true;
       }
       else {
-	this._regex = false;
+	      this._regex = false;
       };
       this._update();
     };
@@ -128,8 +128,8 @@
     re.addEventListener(
       'click',
       function (e) {
-	this.toggleRegex();
-	e.halt();
+	      this.toggleRegex();
+	      e.halt();
       }.bind(this),
       true
     );
@@ -138,19 +138,19 @@
     e.addEventListener(
       'blur',
       function (e) {
-	this.store(this.value(), this.regex());
-	e.halt();
+	      this.store(this.value(), this.regex());
+	      e.halt();
       }.bind(this)
     );
 
     this._input.addEventListener(
       'keypress',
       function (e) {
-	if (e.keyCode == 13) {
-	  this.value(this._input.value);
-	  this.store(this.value(), this.regex());
+	      if (e.keyCode == 13) {
+	        this.value(this._input.value);
+	        this.store(this.value(), this.regex());
           return false;
-	};
+	      };
       }.bind(this)
     );