Skip to content

Commit a054f49

Browse files
author
rvanderwerf
committed
issue-11271
1 parent 2a67932 commit a054f49

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

grails-web-common/src/main/groovy/org/grails/web/json/JSONTokener.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ public void skipPast(String to) {
467467
* @return A JSONException object, suitable for throwing
468468
*/
469469
public JSONException syntaxError(String message) {
470-
return new JSONException(message + toString());
470+
471+
return new JSONException(message + toRegexSafeString());
471472
}
472473

473474

@@ -478,6 +479,15 @@ public JSONException syntaxError(String message) {
478479
*/
479480
@Override
480481
public String toString() {
482+
return " at character " + this.myIndex + " of " + this.mySource;
483+
}
484+
485+
/**
486+
* Make a regex safe printable string of this JSONTokener.
487+
*
488+
* @return " at character [this.myIndex] of [this.mySource]"
489+
*/
490+
public String toRegexSafeString() {
481491
int endIndex = mySource.length();
482492
boolean appendDots = false;
483493
if (endIndex > 20) {
@@ -491,6 +501,6 @@ public String toString() {
491501
output.append("...");
492502
}
493503
return Matcher.quoteReplacement(output.toString());
494-
495504
}
505+
496506
}

0 commit comments

Comments
 (0)