From 539ece97f493872ad1564f54cb743d17fcf79edf Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Thu, 9 May 2024 06:53:38 +0200 Subject: [PATCH] Protection against non-parsable Accept-Language header --- .../kotlin/org/jeudego/pairgoth/view/CountriesTool.kt | 4 ++++ view-webapp/src/main/webapp/tour-information.inc.html | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/CountriesTool.kt b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/CountriesTool.kt index 17e5095..9f47f36 100644 --- a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/CountriesTool.kt +++ b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/CountriesTool.kt @@ -2,6 +2,7 @@ package org.jeudego.pairgoth.view import org.apache.velocity.tools.config.ValidScope import org.jeudego.pairgoth.web.WebappManager +import org.slf4j.LoggerFactory import javax.servlet.http.HttpServletRequest @ValidScope("request") @@ -19,12 +20,15 @@ class CountriesTool { countries[iso]?.let { name -> Pair(iso, name) } + } ?: null.also { + logger.warn("could not get country from Accept-Language header: ${request.getHeader("Accept-Language")}") } } public fun getCountries() = countries.entries.sortedBy { it.value } companion object { + val logger = LoggerFactory.getLogger("view") private val langHeaderParser = Regex("(?:\\b(\\*|[a-z]{2})(?:(?:_|-)([a-z]{2}))?)(?:;q=([0-9.]+))?", RegexOption.IGNORE_CASE) public val countries = mapOf( "ad" to "Andorra", diff --git a/view-webapp/src/main/webapp/tour-information.inc.html b/view-webapp/src/main/webapp/tour-information.inc.html index 2aa07df..158e6fb 100644 --- a/view-webapp/src/main/webapp/tour-information.inc.html +++ b/view-webapp/src/main/webapp/tour-information.inc.html @@ -25,7 +25,13 @@