Skip to content

Commit 35cf564

Browse files
committed
3385 - fix for the turkish eye
1 parent ea953cd commit 35cf564

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

src/main/java/graphql/schema/PropertyFetchingImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import graphql.GraphQLException;
44
import graphql.Internal;
55
import graphql.schema.fetching.LambdaFetchingSupport;
6+
import graphql.util.EscapeUtil;
7+
import graphql.util.StringKit;
68
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
810

@@ -12,6 +14,7 @@
1214
import java.lang.reflect.Modifier;
1315
import java.util.Arrays;
1416
import java.util.Comparator;
17+
import java.util.Locale;
1518
import java.util.Map;
1619
import java.util.Objects;
1720
import java.util.Optional;
@@ -213,7 +216,7 @@ private Object getPropertyViaGetterMethod(Object object, String propertyName, Gr
213216
}
214217

215218
private Object getPropertyViaGetterUsingPrefix(Object object, String propertyName, String prefix, MethodFinder methodFinder, Supplier<Object> singleArgumentValue) throws NoSuchMethodException {
216-
String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
219+
String getterName = prefix + StringKit.capitalize(propertyName);
217220
Method method = methodFinder.apply(object.getClass(), getterName);
218221
return invokeMethod(object, singleArgumentValue, method, takesSingleArgumentTypeAsOnlyArgument(method));
219222
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package graphql.util;
2+
3+
import java.util.Locale;
4+
5+
public class StringKit {
6+
7+
public static String capitalize(String s) {
8+
if (s != null && !s.isEmpty()) {
9+
StringBuilder sb = new StringBuilder();
10+
// see https://github.com/graphql-java/graphql-java/issues/3385
11+
sb.append(s.substring(0, 1).toUpperCase(Locale.ROOT));
12+
if (s.length() > 1) {
13+
sb.append(s.substring(1));
14+
}
15+
return sb.toString();
16+
}
17+
return s;
18+
}
19+
20+
}

src/test/groovy/graphql/schema/PropertyDataFetcherTest.groovy

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,38 @@ class PropertyDataFetcherTest extends Specification {
637637
result == "bar"
638638
}
639639

640+
class BaseObject {
641+
private String id
642+
643+
String getId() {
644+
return id
645+
}
646+
647+
void setId(String value) {
648+
id = value;
649+
}
650+
}
651+
652+
class OtherObject extends BaseObject {}
653+
654+
def "Can access private property from base class that starts with i in Turkish"() {
655+
// see https://github.com/graphql-java/graphql-java/issues/3385
656+
given:
657+
Locale oldLocale = Locale.getDefault()
658+
Locale.setDefault(new Locale("tr", "TR"))
659+
660+
def environment = env(new OtherObject(id: "aValue"))
661+
def fetcher = PropertyDataFetcher.fetching("id")
662+
663+
when:
664+
String propValue = fetcher.get(environment)
665+
666+
then:
667+
propValue == 'aValue'
668+
669+
cleanup:
670+
Locale.setDefault(oldLocale)
671+
}
640672
/**
641673
* Classes from issue to ensure we reproduce as reported by customers
642674
*
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package graphql.util
2+
3+
import spock.lang.Specification
4+
5+
class StringKitTest extends Specification {
6+
7+
8+
def "can capitalise"() {
9+
expect:
10+
11+
def actual = StringKit.capitalize(input)
12+
actual == expected
13+
14+
where:
15+
input | expected
16+
null | null
17+
"" | ""
18+
"a" | "A"
19+
"abc" | "Abc"
20+
21+
}
22+
}

0 commit comments

Comments
 (0)