From 249be10000912b5bb6270d3a8658e9a5fbeff6d2 Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Wed, 10 Feb 2010 05:38:56 +0000 Subject: [PATCH] SOLR-1767: dataimporter.functions.escapeSql() does not escape backslash character git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@908357 13f79535-47bb-0310-9956-ffa450edef68 --- contrib/dataimporthandler/CHANGES.txt | 2 ++ .../org/apache/solr/handler/dataimport/EvaluatorBag.java | 5 ++++- .../org/apache/solr/handler/dataimport/TestEvaluatorBag.java | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/contrib/dataimporthandler/CHANGES.txt b/contrib/dataimporthandler/CHANGES.txt index c2a40d31931..4ab33653da1 100644 --- a/contrib/dataimporthandler/CHANGES.txt +++ b/contrib/dataimporthandler/CHANGES.txt @@ -61,6 +61,8 @@ Bug Fixes * SOLR-1766: DIH with threads enabled doesn't respond to the abort command (Michael Henson via noble) +* SOLR-1767: dataimporter.functions.escapeSql() does not escape backslash character (Sean Timm via noble) + Other Changes ---------------------- diff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/EvaluatorBag.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/EvaluatorBag.java index dd59c049849..6e623f5eaee 100644 --- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/EvaluatorBag.java +++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/EvaluatorBag.java @@ -72,7 +72,10 @@ public class EvaluatorBag { throw new DataImportHandlerException(SEVERE, "'escapeSql' must have at least one parameter "); } String s = l.get(0).toString(); - return s.replaceAll("'", "''").replaceAll("\"", "\"\""); + // escape single quote with two single quotes, double quote + // with two doule quotes, and backslash with double backslash. + // See: http://dev.mysql.com/doc/refman/4.1/en/mysql-real-escape-string.html + return s.replaceAll("'", "''").replaceAll("\"", "\"\"").replaceAll("\\\\", "\\\\\\\\"); } }; } diff --git a/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestEvaluatorBag.java b/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestEvaluatorBag.java index 902b8bd0268..98006c327b1 100644 --- a/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestEvaluatorBag.java +++ b/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestEvaluatorBag.java @@ -49,6 +49,7 @@ public class TestEvaluatorBag { sqlTests = new HashMap(); sqlTests.put("foo\"", "foo\"\""); + sqlTests.put("foo\\", "foo\\\\"); sqlTests.put("foo'", "foo''"); sqlTests.put("foo''", "foo''''"); sqlTests.put("'foo\"", "''foo\"\"");