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
This commit is contained in:
Yonik Seeley 2006-12-19 17:08:17 +00:00
parent 43fb64bb80
commit 36e388040b
3 changed files with 80 additions and 11 deletions

View File

@ -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 ==================

View File

@ -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;
}
}
}

View File

@ -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<String> 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));
}
}