Skip to content

Commit

Permalink
Merge pull request #87 from nolaviz/nolaviz-devel
Browse files Browse the repository at this point in the history
Fix string comparison to avoid using the collator.
  • Loading branch information
ddekany authored Dec 10, 2023
2 parents f42b107 + 1c274bc commit dbacf3b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/freemarker/core/EvalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package freemarker.core;

import java.lang.reflect.InvocationTargetException;
import java.text.Normalizer;
import java.util.Date;

import freemarker.ext.beans.BeanModel;
Expand Down Expand Up @@ -277,8 +278,12 @@ static boolean compare(
}
String leftString = EvalUtil.modelToString((TemplateScalarModel) leftValue, leftExp, env);
String rightString = EvalUtil.modelToString((TemplateScalarModel) rightValue, rightExp, env);
// FIXME NBC: Don't use the Collator here. That's locale-specific, but ==/!= should not be.
cmpResult = env.getCollator().compare(leftString, rightString);
if (env.getConfiguration().getIncompatibleImprovements().intValue() <= _VersionInts.V_2_3_32) {
cmpResult = env.getCollator().compare(leftString, rightString);
} else {
cmpResult = Normalizer.normalize(leftString, Normalizer.Form.NFKC)
.compareTo(Normalizer.normalize(rightString, Normalizer.Form.NFKC));
}
} else if (leftValue instanceof TemplateBooleanModel && rightValue instanceof TemplateBooleanModel) {
if (operator != CMP_OP_EQUALS && operator != CMP_OP_NOT_EQUALS) {
throw new _MiscTemplateException(defaultBlamed, env,
Expand Down

0 comments on commit dbacf3b

Please sign in to comment.