Skip to content

Commit 4409001

Browse files
Fix tab escape in character gropu and add tests
1 parent 1b7a0f3 commit 4409001

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

sentry/src/main/java/io/sentry/SentryTraceHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class SentryTraceHeader {
1818
// Use numbered capture groups for Android API level < 26 compatibility
1919
private static final Pattern SENTRY_TRACEPARENT_HEADER_REGEX =
2020
Pattern.compile(
21-
"^[ \\t]*([0-9a-f]{32})-([0-9a-f]{16})(-[01])?[ \\t]*$", Pattern.CASE_INSENSITIVE);
21+
"^[ \t]*([0-9a-f]{32})-([0-9a-f]{16})(-[01])?[ \t]*$", Pattern.CASE_INSENSITIVE);
2222

2323
public SentryTraceHeader(
2424
final @NotNull SentryId traceId,

sentry/src/test/java/io/sentry/SentryTraceHeaderTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ class SentryTraceHeaderTest {
132132
assertNull(header.isSampled)
133133
}
134134

135+
@Test
136+
fun `handles header without sampling decision and leading whitespace`() {
137+
val sentryId = SentryId()
138+
val spanId = SpanId()
139+
val header = SentryTraceHeader(" \t $sentryId-$spanId")
140+
assertEquals(sentryId, header.traceId)
141+
assertEquals(spanId, header.spanId)
142+
assertNull(header.isSampled)
143+
}
144+
145+
@Test
146+
fun `handles header without sampling decision and trailing whitespace`() {
147+
val sentryId = SentryId()
148+
val spanId = SpanId()
149+
val header = SentryTraceHeader("$sentryId-$spanId \t ")
150+
assertEquals(sentryId, header.traceId)
151+
assertEquals(spanId, header.spanId)
152+
assertNull(header.isSampled)
153+
}
154+
135155
@Test
136156
fun `when sampling decision is not made, getValue returns header with traceId and spanId`() {
137157
val sentryId = SentryId()

0 commit comments

Comments
 (0)