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 98fd100ea test: cover Locale.ROOT lowercasing paths from #1086 (#1225)
98fd100ea is described below

commit 98fd100ea75fe82be62a0e1c372880415aa73eb0
Author: PJ Fanning <[email protected]>
AuthorDate: Tue Sep 1 08:54:49 2026 +0100

    test: cover Locale.ROOT lowercasing paths from #1086 (#1225)
    
    Motivation:
    #1086 switched a dozen call sites to Locale.ROOT but landed without tests, 
so
    TurkishISpec still only covers HttpCharsets and nothing exercises the 
directives.
    A regression in any of these paths would only show up for users running 
with a
    turkish default locale.
    
    Modification:
    Extend TurkishISpec with cases for `HttpHeader.parse`, `Uri` scheme
    normalization, `MediaTypes.forExtension` and 
`ErrorInfo.withErrorHeaderName`.
    Add TurkishLocaleDirectivesSpec covering `headerValueByName` and
    `overrideMethodWithParameter`, which live in the http module.
    
    Result:
    The header-name, scheme, file-extension, error-header-name, 
header-directive and
    method-override paths are pinned against locale sensitive case conversion.
    
    Tests:
    - sbt "http-core / Test / testOnly 
org.apache.pekko.http.scaladsl.model.TurkishISpec" - 5 passed
    - sbt "http-tests / Test / testOnly 
org.apache.pekko.http.scaladsl.server.directives.TurkishLocaleDirectivesSpec" - 
2 passed; both fail when the two directives are reverted to default-locale case 
conversion
    - sbt headerCreateAll - added the Apache header to the new file
    - scalafmt --mode diff-ref=upstream/main - clean
    
    References:
    Refs #1086
---
 .../pekko/http/scaladsl/model/TurkishISpec.scala   | 29 +++++++++++
 .../directives/TurkishLocaleDirectivesSpec.scala   | 60 ++++++++++++++++++++++
 2 files changed, 89 insertions(+)

diff --git 
a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/TurkishISpec.scala
 
b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/TurkishISpec.scala
index 58d6a89f6..76f9fdede 100644
--- 
a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/TurkishISpec.scala
+++ 
b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/TurkishISpec.scala
@@ -40,5 +40,34 @@ class TurkishISpec extends AnyWordSpec with Matchers {
         Locale.setDefault(previousLocale)
       }
     }
+
+    "parse a header name containing a capital I in the turkish locale" in 
withTurkishLocale {
+      HttpHeader.parse("If-Match", "\"xyzzy\"") match {
+        case HttpHeader.ParsingResult.Ok(header, Nil) => header shouldBe 
a[headers.`If-Match`]
+        case other                                    => fail(s"Expected a 
modelled If-Match header but got $other")
+      }
+    }
+
+    "normalize a uri scheme containing a capital I in the turkish locale" in 
withTurkishLocale {
+      Uri(scheme = "IPP", authority = 
Uri.Authority(Uri.Host("example.com"))).scheme shouldEqual "ipp"
+    }
+
+    "resolve a media type for an upper case file extension in the turkish 
locale" in withTurkishLocale {
+      MediaTypes.forExtension("TIFF") shouldEqual MediaTypes.`image/tiff`
+    }
+
+    "lowercase an error header name in the turkish locale" in 
withTurkishLocale {
+      ErrorInfo("summary", 
"detail").withErrorHeaderName("If-Match").errorHeaderName shouldEqual "if-match"
+    }
+  }
+
+  private def withTurkishLocale(body: => Any): Unit = {
+    val previousLocale = Locale.getDefault
+    try {
+      Locale.setDefault(new Locale("tr", "TR"))
+      body
+    } finally {
+      Locale.setDefault(previousLocale)
+    }
   }
 }
diff --git 
a/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/directives/TurkishLocaleDirectivesSpec.scala
 
b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/directives/TurkishLocaleDirectivesSpec.scala
new file mode 100644
index 000000000..b6ea16264
--- /dev/null
+++ 
b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/directives/TurkishLocaleDirectivesSpec.scala
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.http.scaladsl.server.directives
+
+import java.util.Locale
+
+import org.apache.pekko
+import pekko.http.scaladsl.model.headers.RawHeader
+import pekko.http.scaladsl.server._
+
+/**
+ * Directives that lower- or upper-case a user supplied name must do so with 
`Locale.ROOT`,
+ * otherwise they break in locales like tr-TR where 'I' does not lowercase to 
'i'.
+ */
+class TurkishLocaleDirectivesSpec extends RoutingSpec {
+
+  "The headerValueByName directive" should {
+    "extract a header whose name contains a capital I in the turkish locale" 
in withTurkishLocale {
+      lazy val route = headerValueByName("If-Match") { value => 
complete(value) }
+      Get("abc") ~> RawHeader("If-Match", "\"xyzzy\"") ~> route ~> check {
+        responseAs[String] shouldEqual "\"xyzzy\""
+      }
+    }
+  }
+
+  "The overrideMethodWithParameter directive" should {
+    "override with a method name containing an i in the turkish locale" in 
withTurkishLocale {
+      lazy val route = overrideMethodWithParameter("_method") {
+        get { complete("GET") } ~
+        options { complete("OPTIONS") }
+      }
+      Get("/?_method=options") ~> route ~> check { responseAs[String] 
shouldEqual "OPTIONS" }
+    }
+  }
+
+  private def withTurkishLocale(body: => Any): Unit = {
+    val previousLocale = Locale.getDefault
+    try {
+      Locale.setDefault(new Locale("tr", "TR"))
+      body
+    } finally {
+      Locale.setDefault(previousLocale)
+    }
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to