### Question:
ServletMessageSupplier extends MessageSupplier implements ServletRequestInfo { static @Nullable String maskRequestQueryString(@Nullable String requestQueryString, List<Pattern> maskPatterns) { if (requestQueryString == null) { return null; } if (maskPatterns.isEmpty()) { return requestQueryString; } StringBuilder sb = new StringBuilder(requestQueryString.length()); boolean existMaskedParameters = false; int keyStartIndex = 0; boolean inMaskedValue = false; for (int i = 0; i < requestQueryString.length(); i++) { char c = requestQueryString.charAt(i); switch (c) { case '&': sb.append('&'); keyStartIndex = sb.length(); inMaskedValue = false; break; case '=': if (keyStartIndex == -1) { if (!inMaskedValue) { sb.append(c); } } else { String key = sb.substring(keyStartIndex, sb.length()); sb.append('='); String keyLowerCase = key.toLowerCase(Locale.ENGLISH); if (DetailCapture.matchesOneOf(keyLowerCase, maskPatterns)) { inMaskedValue = true; sb.append(MASK_TEXT); existMaskedParameters = true; } keyStartIndex = -1; } break; default: if (!inMaskedValue) { sb.append(c); } } } if (existMaskedParameters) { return sb.toString(); } else { return requestQueryString; } } ServletMessageSupplier(String requestMethod, String requestContextPath,
            String requestServletPath, @Nullable String requestPathInfo, String requestUri,
            @Nullable String requestQueryString, Map<String, Object> requestHeaders,
            @Nullable String requestRemoteAddr, @Nullable String requestRemoteHost,
            Map<String, String> sessionAttributeMap); @Override Message get(); @Override String getMethod(); @Override String getContextPath(); @Override String getServletPath(); @Override @Nullable String getPathInfo(); @Override String getUri();  }### Answer:
@Test public void shouldMask() { List<Pattern> maskPatterns = ImmutableList.of(Pattern.compile(".*password.*")); String requestQueryString = "test=one&xpasswordy=maskme&test=two"; String maskRequestQueryString = ServletMessageSupplier.maskRequestQueryString(requestQueryString, maskPatterns); assertThat(maskRequestQueryString).isEqualTo("test=one&xpasswordy=****&test=two"); }
@Test public void shouldNotMask() { List<Pattern> maskPatterns = ImmutableList.of(Pattern.compile(".*password.*")); String requestQueryString = "test=one&xpassworry=nomask&test=two"; String maskRequestQueryString = ServletMessageSupplier.maskRequestQueryString(requestQueryString, maskPatterns); assertThat(maskRequestQueryString).isEqualTo("test=one&xpassworry=nomask&test=two"); }
@Test public void shouldMaskStrange() { List<Pattern> maskPatterns = ImmutableList.of(Pattern.compile(".*password.*")); String requestQueryString = "test=one&&&===&=&xpasswordy=mask=me&&&==&test=two"; String maskRequestQueryString = ServletMessageSupplier.maskRequestQueryString(requestQueryString, maskPatterns); assertThat(maskRequestQueryString) .isEqualTo("test=one&&&===&=&xpasswordy=****&&&==&test=two"); }
@Test public void shouldNotMaskStrange() { List<Pattern> maskPatterns = ImmutableList.of(Pattern.compile(".*password.*")); String requestQueryString = "test=one&&&===&=&xpassworry=no=mask&&&==&test=two"; String maskRequestQueryString = ServletMessageSupplier.maskRequestQueryString(requestQueryString, maskPatterns); assertThat(maskRequestQueryString) .isEqualTo("test=one&&&===&=&xpassworry=no=mask&&&==&test=two"); }