Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5824: hunspell FLAG LONG implemented incorrectly

Robert Muir7bb3f6044ea7
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index d1e47be5c2b..9d8efda6331 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -163,6 +163,8 @@ Bug Fixes
match affixes, words are only stripped to a zero-length string if FULLSTRIP option
is specifed in the dictionary. (Robert Muir)
+* LUCENE-5824: Fix hunspell 'long' flag handling. (Robert Muir)
+
Test Framework
* LUCENE-5786: Unflushed/ truncated events file (hung testing subprocess).
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 179887a0a66..e36a9c97588 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
@@ -1063,8 +1063,6 @@ public class Dictionary {
/**
* Implementation of {@link FlagParsingStrategy} that assumes each flag is encoded as two ASCII characters whose codes
* must be combined into a single character.
- *
- * TODO (rmuir) test
*/
private static class DoubleASCIIFlagParsingStrategy extends FlagParsingStrategy {
@@ -1079,8 +1077,13 @@ public class Dictionary {
throw new IllegalArgumentException("Invalid flags (should be even number of characters): " + rawFlags);
}
for (int i = 0; i < rawFlags.length(); i+=2) {
- char cookedFlag = (char) ((int) rawFlags.charAt(i) + (int) rawFlags.charAt(i + 1));
- builder.append(cookedFlag);
+ char f1 = rawFlags.charAt(i);
+ char f2 = rawFlags.charAt(i+1);
+ if (f1 >= 256 || f2 >= 256) {
+ throw new IllegalArgumentException("Invalid flags (LONG flags must be double ASCII): " + rawFlags);
+ }
+ char combined = (char) (f1 << 8 | f2);
+ builder.append(combined);
}
char flags[] = new char[builder.length()];
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestFlagLong.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestFlagLong.java
index c6ab74ce494..5165a240222 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestFlagLong.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestFlagLong.java
@@ -29,5 +29,6 @@ public class TestFlagLong extends StemmerTestBase {
assertStemsTo("foo", "foo");
assertStemsTo("foos", "foo");
assertStemsTo("fooss");
+ assertStemsTo("foobogus");
}
}
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/flaglong.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/flaglong.aff
index d05a5dad747..fb0f4234edc 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/flaglong.aff
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/flaglong.aff
@@ -2,3 +2,6 @@ SET UTF-8
FLAG long
SFX Y1 Y 1
SFX Y1 0 s .
+
+SFX 1Y Y 1
+SFX 1Y 0 bogus .