Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5768: hunspell condition checks with character classes were buggy

Robert Muirdd32343ee2ca
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 217c39228e0..8b6aa79cd5d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -330,6 +330,9 @@ Bug fixes
* LUCENE-5747: Project-specific settings for the eclipse development
environment will prevent automatic code reformatting. (Shawn Heisey)
+* LUCENE-5768: Hunspell condition checks containing character classes
+ were buggy. (Clinton Gormley, Robert Muir)
+
Test Framework
* LUCENE-5622: Fail tests if they print over the given limit of bytes to
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
index 0651e4dd520..b67a978fab2 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
@@ -420,7 +420,7 @@ public class Dictionary {
String condition = ruleArgs.length > 4 ? ruleArgs[4] : ".";
// at least the gascon affix file has this issue
- if (condition.startsWith("[") && !condition.endsWith("]")) {
+ if (condition.startsWith("[") && condition.indexOf(']') == -1) {
condition = condition + "]";
}
// "dash hasn't got special meaning" (we must escape it)
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCondition2.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCondition2.java
new file mode 100644
index 00000000000..9e7234a6490
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCondition2.java
@@ -0,0 +1,32 @@
+package org.apache.lucene.analysis.hunspell;
+
+import org.junit.BeforeClass;
+
+/*
+ * 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.
+ */
+
+public class TestCondition2 extends StemmerTestBase {
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ init("condition2.aff", "condition2.dic");
+ }
+
+ public void testStemming() {
+ assertStemsTo("monopolies", "monopoly");
+ }
+}
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/condition2.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/condition2.aff
new file mode 100644
index 00000000000..8e06a21b2ce
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/condition2.aff
@@ -0,0 +1,5 @@
+SET ISO8859-1
+TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ'
+
+SFX S Y 1
+SFX S y ies [^aeiou]y
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/condition2.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/condition2.dic
new file mode 100644
index 00000000000..72a8c3e7cf5
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/condition2.dic
@@ -0,0 +1,2 @@
+1
+monopoly/S