Skip to content
Snippets Groups Projects

feat: Add list support for FormatHelper

1 file
+ 17
2
Compare changes
  • Side-by-side
  • Inline
@@ -11,6 +11,10 @@
@@ -11,6 +11,10 @@
*/
*/
package org.eclipsefoundation.core.helper;
package org.eclipsefoundation.core.helper;
 
import java.util.Collections;
 
import java.util.List;
 
import java.util.stream.Collectors;
 
/**
/**
* Helpers for use in formatting log messages.
* Helpers for use in formatting log messages.
*
*
@@ -19,8 +23,8 @@ package org.eclipsefoundation.core.helper;
@@ -19,8 +23,8 @@ package org.eclipsefoundation.core.helper;
public final class LoggingHelper {
public final class LoggingHelper {
/**
/**
* Formats the message part to remove newline characters. This is meant to be used for user-defined fields to prevent
* Formats the message part to remove newline characters. This is meant to be used for user-defined fields to prevent logging
* logging injections.
* injections.
*
*
* @param msg the message part to format
* @param msg the message part to format
* @return the sanitized log part.
* @return the sanitized log part.
@@ -32,6 +36,17 @@ public final class LoggingHelper {
@@ -32,6 +36,17 @@ public final class LoggingHelper {
return msg.replaceAll("[\\n\\r]", "__");
return msg.replaceAll("[\\n\\r]", "__");
}
}
 
/**
 
* Formats the message part to remove newline characters from each item in the list. This is meant to be used for user-defined fields to
 
* prevent logging injections.
 
*
 
* @param msg the message part to format
 
* @return the sanitized log part.
 
*/
 
public static List<String> format(List<String> msg) {
 
return msg == null ? Collections.emptyList() : msg.stream().map(LoggingHelper::format).collect(Collectors.toList());
 
}
 
private LoggingHelper() {
private LoggingHelper() {
}
}
}
}
Loading