Skip to content

Commit

Permalink
[JENKINS-41760] Broken output when empty secret - check for empty sec…
Browse files Browse the repository at this point in the history
…rets during pattern creation
  • Loading branch information
Michal Slusarczyk committed Apr 27, 2017
1 parent 3a0ec0d commit 6a7a806
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Expand Up @@ -188,10 +188,12 @@ public static String getPatternStringForSecrets(Collection<String> secrets) {
Collections.sort(sortedByLength, stringLengthComparator);

for (String secret : sortedByLength) {
if (b.length() > 0) {
b.append('|');
if (!secret.isEmpty()) {
if (b.length() > 0) {
b.append('|');
}
b.append(Pattern.quote(secret));
}
b.append(Pattern.quote(secret));
}
return b.toString();
}
Expand Down
Expand Up @@ -174,9 +174,14 @@ private Object readResolve() throws ObjectStreamException {
final Pattern p = Pattern.compile(pattern.getPlainText());
return new LineTransformationOutputStream() {
@Override protected void eol(byte[] b, int len) throws IOException {
Matcher m = p.matcher(new String(b, 0, len, charsetName));
if (m.find()) {
logger.write(m.replaceAll("****").getBytes(charsetName));
if (!p.toString().isEmpty()) {
Matcher m = p.matcher(new String(b, 0, len, charsetName));
if (m.find()) {
logger.write(m.replaceAll("****").getBytes(charsetName));
} else {
// Avoid byte → char → byte conversion unless we are actually doing something.
logger.write(b, 0, len);
}
} else {
// Avoid byte → char → byte conversion unless we are actually doing something.
logger.write(b, 0, len);
Expand Down
Expand Up @@ -149,7 +149,7 @@ private static final class Filter extends ConsoleLogFilter {
p = getPatternForBuild(build);
}

if (p != null) {
if (p != null && !p.toString().isEmpty()) {
Matcher m = p.matcher(new String(b, 0, len, charsetName));
if (m.find()) {
logger.write(m.replaceAll("****").getBytes(charsetName));
Expand Down

0 comments on commit 6a7a806

Please sign in to comment.