Skip to content

Commit

Permalink
Merge pull request #601 from renekrie/issue600
Browse files Browse the repository at this point in the history
Avoid InvalidPathException in RelationalOperator, fixes #600
  • Loading branch information
kallestenflo authored Dec 10, 2020
2 parents 8420a6d + 698dbfa commit ba35cf9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.jayway.jsonpath.InvalidPathException;

import java.util.Locale;

public enum RelationalOperator {

GTE(">="),
Expand Down Expand Up @@ -40,9 +42,10 @@ public enum RelationalOperator {
this.operatorString = operatorString;
}

public static RelationalOperator fromString(String operatorString){
public static RelationalOperator fromString(String operatorString) {
String upperCaseOperatorString = operatorString.toUpperCase(Locale.ROOT);
for (RelationalOperator operator : RelationalOperator.values()) {
if(operator.operatorString.equals(operatorString.toUpperCase()) ){
if(operator.operatorString.equals(upperCaseOperatorString) ){
return operator;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.jayway.jsonpath.internal.filter;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.Locale;

public class RelationalOperatorTest {

Locale locale;

@Before
public void saveDefaultLocale() {
locale = Locale.getDefault();
}

@After
public void restoreDefaultLocale() {
Locale.setDefault(locale);
}

@Test
public void testFromStringWithEnglishLocale() {
Locale.setDefault(Locale.ENGLISH);
assertEquals(RelationalOperator.IN, RelationalOperator.fromString("in"));
assertEquals(RelationalOperator.IN, RelationalOperator.fromString("IN"));
}

@Test
public void testFromStringWithTurkishLocale() {
Locale.setDefault(new Locale("tr", "TR"));
assertEquals(RelationalOperator.IN, RelationalOperator.fromString("in"));
assertEquals(RelationalOperator.IN, RelationalOperator.fromString("IN"));
}

}

0 comments on commit ba35cf9

Please sign in to comment.