Browse Source

Merge pull request #601 from renekrie/issue600

Avoid InvalidPathException in RelationalOperator, fixes #600
pull/649/head
kallestenflo 4 years ago committed by GitHub
parent
commit
ba35cf9c6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/RelationalOperator.java
  2. 39
      json-path/src/test/java/com/jayway/jsonpath/internal/filter/RelationalOperatorTest.java

7
json-path/src/main/java/com/jayway/jsonpath/internal/filter/RelationalOperator.java

@ -2,6 +2,8 @@ package com.jayway.jsonpath.internal.filter;
import com.jayway.jsonpath.InvalidPathException;
import java.util.Locale;
public enum RelationalOperator {
GTE(">="),
@ -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;
}
}

39
json-path/src/test/java/com/jayway/jsonpath/internal/filter/RelationalOperatorTest.java

@ -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"));
}
}
Loading…
Cancel
Save