You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/06/19 14:16:23 UTC
svn commit: r1603856 - in /lucene/dev/branches/lucene_solr_4_9: ./ lucene/
lucene/analysis/
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/
lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/
Author: rmuir
Date: Thu Jun 19 12:16:23 2014
New Revision: 1603856
URL: http://svn.apache.org/r1603856
Log:
LUCENE-5777: fix double escaping of dash in hunspell conditions
Added:
lucene/dev/branches/lucene_solr_4_9/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDoubleEscape.java
- copied unchanged from r1603853, lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDoubleEscape.java
lucene/dev/branches/lucene_solr_4_9/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/double-escaped.aff
- copied unchanged from r1603853, lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/double-escaped.aff
lucene/dev/branches/lucene_solr_4_9/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/double-escaped.dic
- copied unchanged from r1603853, lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/double-escaped.dic
Modified:
lucene/dev/branches/lucene_solr_4_9/ (props changed)
lucene/dev/branches/lucene_solr_4_9/lucene/ (props changed)
lucene/dev/branches/lucene_solr_4_9/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/lucene_solr_4_9/lucene/analysis/ (props changed)
lucene/dev/branches/lucene_solr_4_9/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
Modified: lucene/dev/branches/lucene_solr_4_9/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_9/lucene/CHANGES.txt?rev=1603856&r1=1603855&r2=1603856&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_9/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_9/lucene/CHANGES.txt Thu Jun 19 12:16:23 2014
@@ -244,7 +244,7 @@ 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
+* LUCENE-5768, LUCENE-5777: Hunspell condition checks containing character classes
were buggy. (Clinton Gormley, Robert Muir)
Test Framework
Modified: lucene/dev/branches/lucene_solr_4_9/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_9/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java?rev=1603856&r1=1603855&r2=1603856&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_9/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java (original)
+++ lucene/dev/branches/lucene_solr_4_9/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java Thu Jun 19 12:16:23 2014
@@ -356,6 +356,25 @@ public class Dictionary {
}
return builder.finish();
}
+
+ static String escapeDash(String re) {
+ // we have to be careful, even though dash doesn't have a special meaning,
+ // some dictionaries already escape it (e.g. pt_PT), so we don't want to nullify it
+ StringBuilder escaped = new StringBuilder();
+ for (int i = 0; i < re.length(); i++) {
+ char c = re.charAt(i);
+ if (c == '-') {
+ escaped.append("\\-");
+ } else {
+ escaped.append(c);
+ if (c == '\\' && i + 1 < re.length()) {
+ escaped.append(re.charAt(i+1));
+ i++;
+ }
+ }
+ }
+ return escaped.toString();
+ }
/**
* Parses a specific affix rule putting the result into the provided affix map
@@ -425,7 +444,7 @@ public class Dictionary {
}
// "dash hasn't got special meaning" (we must escape it)
if (condition.indexOf('-') >= 0) {
- condition = condition.replace("-", "\\-");
+ condition = escapeDash(condition);
}
final String regex;