Skip to content

Commit ce1e7c8

Browse files
author
Francisco Cavedon
authored
Merge pull request #45 from Shopify/bug/10843-fix-dashes-in-beta-flags
Adding new sanity check
2 parents 134e0fb + 3ab95db commit ce1e7c8

2 files changed

Lines changed: 14 additions & 22 deletions

File tree

support/src/main/java/com/shopify/graphql/support/Query.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
public abstract class Query<T extends Query> {
77
public static final String ALIAS_SUFFIX_SEPARATOR = "__";
8+
private static final String BAD_ALIAS_SEPARATOR = "-";
89
private static final String ALIAS_DELIMITER = ":";
910
protected final StringBuilder _queryBuilder;
1011
private boolean firstSelection = true;
@@ -82,6 +83,9 @@ public T withAlias(String aliasSuffix) {
8283
if (aliasSuffix.contains(Query.ALIAS_SUFFIX_SEPARATOR)) {
8384
throw new IllegalArgumentException("Alias must not contain __");
8485
}
86+
if (aliasSuffix.contains(Query.BAD_ALIAS_SEPARATOR)) {
87+
throw new IllegalArgumentException("Alias must not contain -");
88+
}
8589
this.aliasSuffix = aliasSuffix;
8690
// noinspection unchecked
8791
return (T) this;

support/src/test/java/com/shopify/graphql/support/QueryTest.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.junit.Test;
44

55
import static junit.framework.Assert.assertEquals;
6-
import static org.junit.Assert.assertTrue;
76

87
public class QueryTest {
98
@Test
@@ -13,29 +12,18 @@ public void testStringEscaping() throws Exception {
1312
assertEquals("\"\\u0000 \\r \\n \\\\ \\\" c ꝏ\"", result.toString());
1413
}
1514

16-
@Test
17-
public void testInvalidAlias() {
18-
boolean exceptionThrown = false;
19-
try {
20-
new Query<Query>(null) {
21-
}.withAlias("invalid__alias");
22-
} catch (IllegalArgumentException e) {
23-
exceptionThrown = true;
24-
} finally {
25-
assertTrue(exceptionThrown);
26-
}
15+
@Test(expected = IllegalArgumentException.class)
16+
public void testInvalidAliasWithUnderscore() {
17+
new Query<Query>(null) {}.withAlias("invalid__alias");
2718
}
2819

29-
@Test
20+
@Test(expected = IllegalArgumentException.class)
21+
public void testInvalidAliasWithDashes() {
22+
new Query<Query>(null) {}.withAlias("invalid-alias");
23+
}
24+
25+
@Test(expected = IllegalArgumentException.class)
3026
public void testBlankAlias() {
31-
boolean exceptionThrown = false;
32-
try {
33-
new Query<Query>(null) {
34-
}.withAlias("");
35-
} catch (IllegalArgumentException e) {
36-
exceptionThrown = true;
37-
} finally {
38-
assertTrue(exceptionThrown);
39-
}
27+
new Query<Query>(null) {}.withAlias("");
4028
}
4129
}

0 commit comments

Comments
 (0)