Fixed escaping of verbatim keys in Poliqarp

Change-Id: Ida1f76fe73dc14e3198c5a31f40e67b10aa71c11
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
index c64bf6f..76162d0 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
@@ -30,6 +30,7 @@
  * 
  * @author Michael Hanl (hanl@ids-mannheim.de)
  * @author Joachim Bingel (bingel@ids-mannheim.de)
+ * @author Nils Diewald (diewald@ids-mannheim.de)
  * @version 0.3.0
  * @since 0.1.0
  */
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
index 7727011..922db7f 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
@@ -35,6 +35,7 @@
  * 
  * @author Joachim Bingel (bingel@ids-mannheim.de)
  * @author Eliza Margaretha (margaretha@ids-mannheim.de)
+ * @author Nils Diewald (diewald@ids-mannheim.de)
  * @version 0.3.0
  * @since 0.1.0
  */
@@ -808,7 +809,7 @@
 				key = stream.getText(keyNode.getChild(0).getSourceInterval());
 
 				if (key.startsWith("'") && key.endsWith("'"))
-					key = key.substring(1, key.length()-1);
+					key = key.substring(1, key.length()-1).replaceAll("\\\\\\\\","\\\\").replaceAll("\\\\'", "'");
 
 			}
 			else {
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
index 9e8771e..f59d769 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
@@ -139,11 +139,11 @@
         assertEquals("mate", res.at("/query/wrap/foundry").asText());
         assertEquals("match:eq", res.at("/query/wrap/match").asText());
 
-		query = "[mate/b='D\\'Ma nn']";
+		query = "[mate/b='D\\'Ma \\\\nn']";
         qs.setQuery(query, "poliqarpplus");
 		assertFalse(qs.hasErrors());
 		res = mapper.readTree(qs.toJSON());
-        assertEquals("D\\'Ma nn", res.at("/query/wrap/key").asText());
+        assertEquals("D'Ma \\nn", res.at("/query/wrap/key").asText());
 	}