Skip to content

Commit

Permalink
Ignore whitespace in label and structured metadata patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
nehaev committed Oct 29, 2024
1 parent b942b13 commit 34e971f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ static String[] extractKVPairsFromPattern(String pattern, String pairSeparator,

var kv = keyValueSeparatorPattern.split(pairs[i]);
if (kv.length == 2) {
result[pos] = kv[0];
result[pos + 1] = kv[1];
result[pos] = kv[0].trim();
result[pos + 1] = kv[1].trim();
pos += 2;
} else {
throw new IllegalArgumentException(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public void testExtractStreamKVPairsIgnoringEmpty() {
assertArrayEquals("Split by ,=", kvse1, kvs1);
}

@Test
public void testExtractStreamKVPairsIgnoringWhitespace() {
var kvs1 = AbstractLoki4jEncoder.extractKVPairsFromPattern("\tlevel = %level,\n\tapp=\"my\"app,\n", ",", "=");
var kvse1 = new String[] {"level", "%level", "app", "\"my\"app"};
assertArrayEquals("Split by ,=", kvse1, kvs1);
}

@Test
public void testExtractStreamKVPairsByRegex() {
var kvs1 = AbstractLoki4jEncoder.extractKVPairsFromPattern(
Expand Down

0 comments on commit 34e971f

Please sign in to comment.