File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,7 +50,11 @@ private GraphqlErrorBuilder() {
5050 }
5151
5252 public GraphqlErrorBuilder message (String message , Object ... formatArgs ) {
53- this .message = String .format (assertNotNull (message ), formatArgs );
53+ if (formatArgs == null || formatArgs .length == 0 ) {
54+ this .message = assertNotNull (message );
55+ } else {
56+ this .message = String .format (assertNotNull (message ), formatArgs );
57+ }
5458 return this ;
5559 }
5660
Original file line number Diff line number Diff line change @@ -76,4 +76,38 @@ class GraphqlErrorBuilderTest extends Specification {
7676 graphQLError. getPath() == [" field" ]
7777 graphQLError. getLocations() == [new SourceLocation (1 , 3 )]
7878 }
79+
80+ def " java string format is safe" () {
81+ when :
82+ def gqlErr = GraphqlErrorBuilder . newError(). message(" This has %s in it" ). build()
83+ then :
84+ gqlErr. getMessage() == " This has %s in it"
85+
86+ when :
87+ gqlErr = GraphqlErrorBuilder . newError(). message(" This has %s in it" , null ). build()
88+ then :
89+ gqlErr. getMessage() == " This has %s in it"
90+
91+ when :
92+ gqlErr = GraphqlErrorBuilder . newError(). message(" This has %s in it" , new Object [0 ]). build()
93+ then :
94+ gqlErr. getMessage() == " This has %s in it"
95+
96+ when :
97+ gqlErr = GraphqlErrorBuilder . newError(). message(" This has %s in it" , " data" ). build()
98+ then :
99+ gqlErr. getMessage() == " This has data in it"
100+ }
101+
102+ def " null message is not acceptable" () {
103+ when :
104+ GraphqlErrorBuilder . newError(). message(null , " a" , " b" ). build()
105+ then :
106+ thrown(AssertException )
107+
108+ when :
109+ GraphqlErrorBuilder . newError(). message(null ). build()
110+ then :
111+ thrown(AssertException )
112+ }
79113}
You can’t perform that action at this time.
0 commit comments