Skip to content

fix: use root locale when looking up a response header by name in RouteTest - #1223

Merged
pjfanning merged 1 commit into
apache:mainfrom
pjfanning:fix/testkit-route-test-turkish-i
Aug 24, 2026
Merged

fix: use root locale when looking up a response header by name in RouteTest#1223
pjfanning merged 1 commit into
apache:mainfrom
pjfanning:fix/testkit-route-test-turkish-i

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Motivation

RouteTest#header(name: String) in the Scala testkit lowercased the supplied header name using the JVM default locale:

def header(name: String): Option[HttpHeader] = rawResponse.headers.find(_.is(name.toLowerCase))

HttpHeader#lowercaseName is built with toRootLowerCase, so under a Turkish default locale the two disagree: "If-Match".toLowerCase is ıf-match (dotless i) while lowercaseName is if-match. Any header name containing a capital I then silently resolves to None.

The rest of the code base already guards against this (Helpers.toRootLowerCase, CharUtils.toLowerCase for the ASCII-only paths, and HttpCharsets has a regression test in TurkishISpec). The javadsl equivalent, javadsl/testkit/TestRouteResult, already uses toRootLowerCase — only the scaladsl side was missed.

Modification

Use pekko.util.Helpers.toRootLowerCase in RouteTest#header(name).

Result

Header lookup by name in the Scala testkit is locale independent and consistent with both HttpHeader#lowercaseName and the javadsl testkit.

Tests

  • Added a regression test to ScalatestRouteTestSpec that sets the default locale to tr-TR (restoring it in a finally) and looks up an If-Match header by name. It fails with None was not equal to Some(If-Match: "xyzzy") before the fix and passes after it.
  • sbt "http-testkit / Test / testOnly org.apache.pekko.http.scaladsl.testkit.ScalatestRouteTestSpec" - 12 tests passed (JDK 21).
  • scalafmt --mode diff-ref=origin/main - clean.
  • sbt +mimaReportBinaryIssues - not run; this is a method body change with no public API or binary shape change.

References

None - found while auditing the code base for locale sensitive lowercasing

…teTest

Motivation:
`RouteTest#header(name: String)` lowercased the given header name with the
JVM default locale before comparing it to `HttpHeader#lowercaseName`, which
is built with `toRootLowerCase`. Under a Turkish locale `"If-Match".toLowerCase`
yields a dotless i, so the lookup silently returned `None` for any header name
containing a capital `I`. The javadsl equivalent (`TestRouteResult`) already
uses `toRootLowerCase`.

Modification:
Use `pekko.util.Helpers.toRootLowerCase` in `RouteTest#header(name)`.

Result:
Header lookup by name in the Scala testkit is locale independent and matches
the javadsl behaviour.

Tests:
- sbt "http-testkit / Test / testOnly org.apache.pekko.http.scaladsl.testkit.ScalatestRouteTestSpec" - passes with the fix; the new test fails without it
- scalafmt --mode diff-ref=origin/main - clean
- sbt +mimaReportBinaryIssues - not run; method body change only, no API or binary shape change

References:
None - found while auditing the code base for locale sensitive lowercasing
@pjfanning pjfanning added this to the 2.0.0-M2 milestone Aug 24, 2026
@pjfanning
pjfanning merged commit 08e174c into apache:main Aug 24, 2026
6 checks passed
@pjfanning
pjfanning deleted the fix/testkit-route-test-turkish-i branch August 24, 2026 11:18
pjfanning added a commit to pjfanning/incubator-pekko-http that referenced this pull request Aug 24, 2026
…teTest (apache#1223)

Motivation:
`RouteTest#header(name: String)` lowercased the given header name with the
JVM default locale before comparing it to `HttpHeader#lowercaseName`, which
is built with `toRootLowerCase`. Under a Turkish locale `"If-Match".toLowerCase`
yields a dotless i, so the lookup silently returned `None` for any header name
containing a capital `I`. The javadsl equivalent (`TestRouteResult`) already
uses `toRootLowerCase`.

Modification:
Use `pekko.util.Helpers.toRootLowerCase` in `RouteTest#header(name)`.

Result:
Header lookup by name in the Scala testkit is locale independent and matches
the javadsl behaviour.

Tests:
- sbt "http-testkit / Test / testOnly org.apache.pekko.http.scaladsl.testkit.ScalatestRouteTestSpec" - passes with the fix; the new test fails without it
- scalafmt --mode diff-ref=origin/main - clean
- sbt +mimaReportBinaryIssues - not run; method body change only, no API or binary shape change

References:
None - found while auditing the code base for locale sensitive lowercasing

(cherry picked from commit 08e174c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants