@@ -167,20 +167,17 @@ private static String redactUserInfo(String url) {
167
167
private static String redactQueryParameters (String url ) {
168
168
169
169
int questionMarkIndex = url .indexOf ('?' );
170
-
171
- if (questionMarkIndex == -1 ) {
172
- return url ;
173
- }
174
-
175
- if (!containsParamToRedact (url )) {
170
+ if (questionMarkIndex == -1 || !containsParamToRedact (url )) {
176
171
return url ;
177
172
}
178
173
179
174
StringBuilder redactedParameters = new StringBuilder ();
180
- boolean paramToRedact = false ;
175
+ boolean paramToRedact = false ; // To be able to skip the characters of the parameters to redact
181
176
boolean paramNameDetected = false ;
182
177
boolean reference = false ;
183
178
179
+ // To build a parameter name until we reach the '=' character
180
+ // If the parameter name is a one to redact, we will redact the value
184
181
StringBuilder currentParamName = new StringBuilder ();
185
182
186
183
for (int i = questionMarkIndex + 1 ; i < url .length (); i ++) {
@@ -193,12 +190,13 @@ private static String redactQueryParameters(String url) {
193
190
redactedParameters .append ("REDACTED" );
194
191
paramToRedact = true ;
195
192
}
196
- } else if (currentChar == '&' ) {
193
+ } else if (currentChar == '&' ) { // New parameter delimiter
197
194
redactedParameters .append ('&' );
198
195
paramNameDetected = false ;
199
196
paramToRedact = false ;
200
- currentParamName .setLength (0 );
201
- } else if (currentChar == '#' ) {
197
+ currentParamName .setLength (
198
+ 0 ); // To avoid creating a new StringBuilder for each new parameter
199
+ } else if (currentChar == '#' ) { // Reference delimiter
202
200
reference = true ;
203
201
redactedParameters .append ('#' );
204
202
} else if (!paramNameDetected ) {
0 commit comments