Skip to content

Commit

Permalink
Merge pull request #3388 from graphql-java/3385-turkish-evil-eye
Browse files Browse the repository at this point in the history
3385 - fix for the turkish eye 🧿
  • Loading branch information
dondonz committed Jan 23, 2024
2 parents aaadae2 + 5a9ee92 commit f059f50
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/main/java/graphql/schema/PropertyFetchingImpl.java
Expand Up @@ -3,6 +3,8 @@
import graphql.GraphQLException;
import graphql.Internal;
import graphql.schema.fetching.LambdaFetchingSupport;
import graphql.util.EscapeUtil;
import graphql.util.StringKit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,6 +14,7 @@
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -213,7 +216,7 @@ private Object getPropertyViaGetterMethod(Object object, String propertyName, Gr
}

private Object getPropertyViaGetterUsingPrefix(Object object, String propertyName, String prefix, MethodFinder methodFinder, Supplier<Object> singleArgumentValue) throws NoSuchMethodException {
String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
String getterName = prefix + StringKit.capitalize(propertyName);
Method method = methodFinder.apply(object.getClass(), getterName);
return invokeMethod(object, singleArgumentValue, method, takesSingleArgumentTypeAsOnlyArgument(method));
}
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/graphql/schema/diff/SchemaDiff.java
Expand Up @@ -38,6 +38,7 @@
import static graphql.language.TypeKind.getTypeKind;
import static graphql.schema.idl.TypeInfo.getAstDesc;
import static graphql.schema.idl.TypeInfo.typeInfo;
import static graphql.util.StringKit.capitalize;

/**
* The SchemaDiff is called with a {@link DiffSet} and will report the
Expand Down Expand Up @@ -972,15 +973,6 @@ private <T> Map<String, T> sortedMap(List<T> listOfNamedThings, Function<T, Stri
return new TreeMap<>(map);
}

private static String capitalize(String name) {
if (name != null && name.length() != 0) {
char[] chars = name.toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
return new String(chars);
} else {
return name;
}
}

private String mkDotName(String... objectNames) {
return String.join(".", objectNames);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/graphql/util/StringKit.java
@@ -0,0 +1,20 @@
package graphql.util;

import java.util.Locale;

public class StringKit {

public static String capitalize(String s) {
if (s != null && !s.isEmpty()) {
StringBuilder sb = new StringBuilder();
// see https://github.com/graphql-java/graphql-java/issues/3385
sb.append(s.substring(0, 1).toUpperCase(Locale.ROOT));
if (s.length() > 1) {
sb.append(s.substring(1));
}
return sb.toString();
}
return s;
}

}
32 changes: 32 additions & 0 deletions src/test/groovy/graphql/schema/PropertyDataFetcherTest.groovy
Expand Up @@ -637,6 +637,38 @@ class PropertyDataFetcherTest extends Specification {
result == "bar"
}

class BaseObject {
private String id

String getId() {
return id
}

void setId(String value) {
id = value;
}
}

class OtherObject extends BaseObject {}

def "Can access private property from base class that starts with i in Turkish"() {
// see https://github.com/graphql-java/graphql-java/issues/3385
given:
Locale oldLocale = Locale.getDefault()
Locale.setDefault(new Locale("tr", "TR"))

def environment = env(new OtherObject(id: "aValue"))
def fetcher = PropertyDataFetcher.fetching("id")

when:
String propValue = fetcher.get(environment)

then:
propValue == 'aValue'

cleanup:
Locale.setDefault(oldLocale)
}
/**
* Classes from issue to ensure we reproduce as reported by customers
*
Expand Down
22 changes: 22 additions & 0 deletions src/test/groovy/graphql/util/StringKitTest.groovy
@@ -0,0 +1,22 @@
package graphql.util

import spock.lang.Specification

class StringKitTest extends Specification {


def "can capitalise"() {
expect:

def actual = StringKit.capitalize(input)
actual == expected

where:
input | expected
null | null
"" | ""
"a" | "A"
"abc" | "Abc"

}
}

0 comments on commit f059f50

Please sign in to comment.