Skip to content
This repository was archived by the owner on Jan 15, 2020. It is now read-only.

Commit 7972f53

Browse files
anshulgangwardevdeep
authored andcommitted
CLOUDSTACK-7575: improved performance of cleanString method in StringUtils
1 parent ec1123a commit 7972f53

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

utils/src/com/cloud/utils/StringUtils.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ public static String getMaskedPasswordForDisplay(String password) {
159159
}
160160

161161
// removes a password request param and it's value, also considering password is in query parameter value which has been url encoded
162-
private static final Pattern REGEX_PASSWORD_QUERYSTRING = Pattern.compile("(&|%26)?[^(&|%26)]*((p|P)assword|accesskey|secretkey)(=|%3D).*?(?=(%26|[&'\"]))");
163-
164-
private static final Pattern REGEX_END_PASSWORD_QUERYSTRING = Pattern.compile("(&|%26)[^(&|%26)]*((p|P)assword|accesskey|secretkey)(=|%3D).*");
162+
private static final Pattern REGEX_PASSWORD_QUERYSTRING = Pattern.compile("(&|%26)?[^(&|%26)]*((p|P)assword|accesskey|secretkey)(=|%3D).*?(?=(%26|[&'\"]|$))");
165163

166164
// removes a password/accesskey/ property from a response json object
167165
private static final Pattern REGEX_PASSWORD_JSON = Pattern.compile("\"((p|P)assword|accesskey|secretkey)\":\\s?\".*?\",?");
@@ -177,7 +175,6 @@ public static String cleanString(String stringToClean) {
177175
String cleanResult = "";
178176
if (stringToClean != null) {
179177
cleanResult = REGEX_PASSWORD_QUERYSTRING.matcher(stringToClean).replaceAll("");
180-
cleanResult = REGEX_END_PASSWORD_QUERYSTRING.matcher(cleanResult).replaceAll("");
181178
cleanResult = REGEX_PASSWORD_JSON.matcher(cleanResult).replaceAll("");
182179
Matcher detailsMatcher = REGEX_PASSWORD_DETAILS.matcher(cleanResult);
183180
while (detailsMatcher.find()) {

0 commit comments

Comments
 (0)