From 36e388040b294365e1246c9dd6251540fe2bfc19 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Tue, 19 Dec 2006 17:08:17 +0000 Subject: [PATCH] fix escapes in StrUtils.split*: SOLR-87 git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@488728 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 8 ++- src/java/org/apache/solr/util/StrUtils.java | 20 +++---- src/test/org/apache/solr/util/TestUtils.java | 63 ++++++++++++++++++++ 3 files changed, 80 insertions(+), 11 deletions(-) create mode 100755 src/test/org/apache/solr/util/TestUtils.java diff --git a/CHANGES.txt b/CHANGES.txt index c325e4d619d..98043e4d0ca 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -35,14 +35,20 @@ Detailed Change List -------------------- New Features + 1. Changes in runtime behavior + 1. Optimizations + 1. Bug Fixes - + 1. SOLR-87: Parsing of synonym files did not correctly handle escaped + whitespace such as \r\n\t\b\f. (yonik) + Other Changes + 1. ================== Release 1.1.0, YYYYMMDD ================== diff --git a/src/java/org/apache/solr/util/StrUtils.java b/src/java/org/apache/solr/util/StrUtils.java index 3030c3df9c2..b92abcdc294 100644 --- a/src/java/org/apache/solr/util/StrUtils.java +++ b/src/java/org/apache/solr/util/StrUtils.java @@ -93,11 +93,11 @@ public class StrUtils { ch = s.charAt(pos++); if (decode) { switch(ch) { - case 'n' : ch='\n'; - case 't' : ch='\t'; - case 'r' : ch='\r'; - case 'b' : ch='\b'; - case 'f' : ch='\f'; + case 'n' : ch='\n'; break; + case 't' : ch='\t'; break; + case 'r' : ch='\r'; break; + case 'b' : ch='\b'; break; + case 'f' : ch='\f'; break; } } } @@ -134,11 +134,11 @@ public class StrUtils { ch = s.charAt(pos++); if (decode) { switch(ch) { - case 'n' : ch='\n'; - case 't' : ch='\t'; - case 'r' : ch='\r'; - case 'b' : ch='\b'; - case 'f' : ch='\f'; + case 'n' : ch='\n'; break; + case 't' : ch='\t'; break; + case 'r' : ch='\r'; break; + case 'b' : ch='\b'; break; + case 'f' : ch='\f'; break; } } } diff --git a/src/test/org/apache/solr/util/TestUtils.java b/src/test/org/apache/solr/util/TestUtils.java new file mode 100755 index 00000000000..31beb5bb33a --- /dev/null +++ b/src/test/org/apache/solr/util/TestUtils.java @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.solr.util; + +import junit.framework.TestCase; + +import java.util.List; + +/** + * @author yonik + * @version $Id$ + */ +public class TestUtils extends TestCase { + public static void testSplitEscaping() { + List arr = StrUtils.splitSmart("\\r\\n:\\t\\f\\b", ":", true); + assertEquals(2,arr.size()); + assertEquals("\r\n",arr.get(0)); + assertEquals("\t\f\b",arr.get(1)); + + arr = StrUtils.splitSmart("\\r\\n:\\t\\f\\b", ":", false); + assertEquals(2,arr.size()); + assertEquals("\\r\\n",arr.get(0)); + assertEquals("\\t\\f\\b",arr.get(1)); + + arr = StrUtils.splitWS("\\r\\n \\t\\f\\b", true); + assertEquals(2,arr.size()); + assertEquals("\r\n",arr.get(0)); + assertEquals("\t\f\b",arr.get(1)); + + arr = StrUtils.splitWS("\\r\\n \\t\\f\\b", false); + assertEquals(2,arr.size()); + assertEquals("\\r\\n",arr.get(0)); + assertEquals("\\t\\f\\b",arr.get(1)); + + arr = StrUtils.splitSmart("\\:foo\\::\\:bar\\:", ":", true); + assertEquals(2,arr.size()); + assertEquals(":foo:",arr.get(0)); + assertEquals(":bar:",arr.get(1)); + + arr = StrUtils.splitWS("\\ foo\\ \\ bar\\ ", true); + assertEquals(2,arr.size()); + assertEquals(" foo ",arr.get(0)); + assertEquals(" bar ",arr.get(1)); + } + + + +}