This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch 1.4.x
in repository https://gitbox.apache.org/repos/asf/pekko-http.git
The following commit(s) were added to refs/heads/1.4.x by this push:
new ef0522094 SSE: allow Unicode line terminators (#1185) (#1186)
ef0522094 is described below
commit ef05220949e0bcfc9aad472033096a23c7eab393
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Jul 27 15:22:26 2026 +0100
SSE: allow Unicode line terminators (#1185) (#1186)
---
.../sse/ServerSentEventParserSpec.scala | 21 +++++++++++++++++++++
.../unmarshalling/sse/ServerSentEventParser.scala | 2 +-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git
a/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/ServerSentEventParserSpec.scala
b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/ServerSentEventParserSpec.scala
index 855f43317..bc23b40fa 100644
---
a/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/ServerSentEventParserSpec.scala
+++
b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/ServerSentEventParserSpec.scala
@@ -77,6 +77,27 @@ final class ServerSentEventParserSpec extends AsyncWordSpec
with Matchers with B
ServerSentEvent("event 3", None, Some("")),
ServerSentEvent("event 4")))
}
+ "parse data values containing Unicode line terminators (U+0085, U+2028,
U+2029)" in {
+ // WHATWG SSE spec: lines end only on CR/LF/CRLF; these Unicode chars
are ordinary content
+ val nel = "\u0085" // NEL
+ val ls = "\u2028" // LINE SEPARATOR
+ val ps = "\u2029" // PARAGRAPH SEPARATOR
+ val input = Vector(
+ s"data: before${nel}after",
+ "",
+ s"data: before${ls}after",
+ "",
+ s"data: before${ps}after",
+ "")
+ Source(input)
+ .via(new ServerSentEventParser(1048576, emitEmptyEvents = false))
+ .runWith(Sink.seq)
+ .map(
+ _ shouldBe Vector(
+ ServerSentEvent(s"before${nel}after"),
+ ServerSentEvent(s"before${ls}after"),
+ ServerSentEvent(s"before${ps}after")))
+ }
"parse ServerSentEvents correctly (and pass empty events)" in {
val input = """|data: event 1 line 1
|data:event 1 line 2
diff --git
a/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/ServerSentEventParser.scala
b/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/ServerSentEventParser.scala
index 6a9a8b0ed..4f734e8c1 100644
---
a/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/ServerSentEventParser.scala
+++
b/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/ServerSentEventParser.scala
@@ -95,7 +95,7 @@ private object ServerSentEventParser {
private final val Retry = "retry"
- private val Field = """([^:]+): ?(.*)""".r
+ private val Field = """(?s)([^:]+): ?(.*)""".r
}
case class OversizedSseEvent(event: ServerSentEvent)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]