From 7e2bc844ad2c099162d96998d40f300c194a5f17 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Mon, 19 Aug 2024 19:51:36 +0200 Subject: [PATCH] Escape XML entities in OpenGotha export --- api-webapp/pom.xml | 5 + .../org/jeudego/pairgoth/ext/OpenGotha.kt | 122 ++++++++++++++++-- 2 files changed, 113 insertions(+), 14 deletions(-) diff --git a/api-webapp/pom.xml b/api-webapp/pom.xml index f84ed7f..799ebfe 100644 --- a/api-webapp/pom.xml +++ b/api-webapp/pom.xml @@ -159,6 +159,11 @@ commons-lang3 3.12.0 + + org.apache.commons + commons-text + 1.8 + commons-io commons-io diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt index 816f9c2..413a48b 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt @@ -2,6 +2,7 @@ package org.jeudego.pairgoth.ext import jakarta.xml.bind.JAXBContext import jakarta.xml.bind.JAXBElement +import org.apache.commons.text.StringEscapeUtils import java.time.LocalDate import org.jeudego.pairgoth.model.* import org.jeudego.pairgoth.opengotha.TournamentType @@ -35,7 +36,8 @@ object OpenGotha { else -> throw Error("Invalid seed system: $str") } - private fun String.titlecase(locale: Locale = Locale.ROOT) = lowercase(locale).replaceFirstChar { it.titlecase(locale) } + private fun String.titleCase(locale: Locale = Locale.ROOT) = lowercase(locale).replaceFirstChar { it.titlecase(locale) } + private fun String.escapeXML() = StringEscapeUtils.escapeXml11(this) private fun MainCritParams.SeedMethod.format() = toString().replace("_", "") @@ -225,7 +227,7 @@ object OpenGotha { player as Player }.joinToString("\n") { player -> """ """ "RESULT_BLACKWINS" @@ -281,7 +284,7 @@ object OpenGotha { game.table }" whitePlayer="${ (tournament.pairables[game.white]!! as Player).let { white -> - "${white.name}${white.firstname}".uppercase(Locale.ENGLISH) // Use Locale.ENGLISH to transform é to É + "${white.name.replace(" ", "")}${white.firstname.replace(" ", "")}".uppercase(Locale.ENGLISH).escapeXML() // Use Locale.ENGLISH to transform é to É } }"/>""" } @@ -304,12 +307,27 @@ object OpenGotha { } - "STDBYOYOMI" TimeSystem.TimeSystemType.CANADIAN -> "CANBYOYOMI" TimeSystem.TimeSystemType.FISCHER -> "FISCHER" - } }" director="${tournament.director}" endDate="${tournament.endDate}" fischerTime="${tournament.timeSystem.increment}" genCountNotPlayedGamesAsHalfPoint="false" genMMBar="${ + } }" director="${ + tournament.director.escapeXML() + }" endDate="${ + tournament.endDate + }" fischerTime="${ + tournament.timeSystem.increment + }" genCountNotPlayedGamesAsHalfPoint="false" genMMBar="${ displayRank( if (tournament.pairing is MacMahon) tournament.pairing.mmBar else 8 ).uppercase(Locale.ROOT) @@ -321,18 +339,94 @@ object OpenGotha { (tournament.pairing.pairingParams.main.mmsValueAbsent * 2).roundToInt() }" genMMS2ValueBye="2" genMMZero="30K" genNBW2ValueAbsent="0" genNBW2ValueBye="2" genRoundDownNBWMMS="${ tournament.pairing.pairingParams.main.roundDownScore - }" komi="${tournament.komi}" location="${tournament.location}" name="${tournament.name}" nbMovesCanTime="${tournament.timeSystem.stones}" numberOfCategories="1" numberOfRounds="${tournament.rounds}" shortName="${tournament.shortName}" size="${tournament.gobanSize}" stdByoYomiTime="${tournament.timeSystem.byoyomi}"/> - + }" komi="${ + tournament.komi + }" location="${ + tournament.location.escapeXML() + }" name="${ + tournament.name.escapeXML() + }" nbMovesCanTime="${ + tournament.timeSystem.stones + }" numberOfCategories="1" numberOfRounds="${ + tournament.rounds + }" shortName="${ + tournament.shortName + }" size="${ + tournament.gobanSize + }" stdByoYomiTime="${ + tournament.timeSystem.byoyomi + }"/> + ${ (0..5).map { - """""" + """""" } } - +