mirror of https://github.com/apache/lucene.git
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:
parent
43fb64bb80
commit
36e388040b
|
@ -35,14 +35,20 @@ Detailed Change List
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
New Features
|
New Features
|
||||||
|
1.
|
||||||
|
|
||||||
Changes in runtime behavior
|
Changes in runtime behavior
|
||||||
|
1.
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
|
1.
|
||||||
|
|
||||||
Bug Fixes
|
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
|
Other Changes
|
||||||
|
1.
|
||||||
|
|
||||||
================== Release 1.1.0, YYYYMMDD ==================
|
================== Release 1.1.0, YYYYMMDD ==================
|
||||||
|
|
||||||
|
|
|
@ -93,11 +93,11 @@ public class StrUtils {
|
||||||
ch = s.charAt(pos++);
|
ch = s.charAt(pos++);
|
||||||
if (decode) {
|
if (decode) {
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'n' : ch='\n';
|
case 'n' : ch='\n'; break;
|
||||||
case 't' : ch='\t';
|
case 't' : ch='\t'; break;
|
||||||
case 'r' : ch='\r';
|
case 'r' : ch='\r'; break;
|
||||||
case 'b' : ch='\b';
|
case 'b' : ch='\b'; break;
|
||||||
case 'f' : ch='\f';
|
case 'f' : ch='\f'; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,11 +134,11 @@ public class StrUtils {
|
||||||
ch = s.charAt(pos++);
|
ch = s.charAt(pos++);
|
||||||
if (decode) {
|
if (decode) {
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'n' : ch='\n';
|
case 'n' : ch='\n'; break;
|
||||||
case 't' : ch='\t';
|
case 't' : ch='\t'; break;
|
||||||
case 'r' : ch='\r';
|
case 'r' : ch='\r'; break;
|
||||||
case 'b' : ch='\b';
|
case 'b' : ch='\b'; break;
|
||||||
case 'f' : ch='\f';
|
case 'f' : ch='\f'; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue