This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-http.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d63dfd35 SSE: allow Unicode line terminators (#1185)
6d63dfd35 is described below

commit 6d63dfd3584877ab88c7f52779d47c9fbd34d490
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Jul 27 14:03:52 2026 +0100

    SSE: allow Unicode line terminators (#1185)
---
 .../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 5228a9c7a..ccceefd9d 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
@@ -78,6 +78,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 c40edf7a5..5bce6ee91 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]

Reply via email to