Skip to content
Permalink
Browse files

[JENKINS-41760] Broken output when empty secret - check for empty sec…

…rets during pattern creation
  • Loading branch information
mslusarczyk committed Apr 27, 2017
1 parent 3a0ec0d commit 6a7a80641ef7821c3fd061522cc4b3dbb9e25563
@@ -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();
}
@@ -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);
@@ -149,7 +149,7 @@ protected Object readResolve() {
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));

0 comments on commit 6a7a806

Please sign in to comment.
You can’t perform that action at this time.