From f508f8384ec6172ff283175b11364a39c44f0ee4 Mon Sep 17 00:00:00 2001 From: Shivam Singh Date: Sat, 5 Apr 2025 18:47:30 +0530 Subject: [PATCH] fix: Properly handle XML special characters in genText to fix flaky test #88 --- .../http4s/fs2data/xml/scalaxml/generators.scala | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/xml-scala/src/test/scala/org/http4s/fs2data/xml/scalaxml/generators.scala b/xml-scala/src/test/scala/org/http4s/fs2data/xml/scalaxml/generators.scala index 3fec27f..da72a41 100644 --- a/xml-scala/src/test/scala/org/http4s/fs2data/xml/scalaxml/generators.scala +++ b/xml-scala/src/test/scala/org/http4s/fs2data/xml/scalaxml/generators.scala @@ -429,16 +429,12 @@ object generators { Attribute(attr.pre, attr.key, attr.value, md) } - val genText: Gen[Text] = - for { - n <- Gen.poisson(5) - s <- Gen.stringOfN(n, Gen.oneOf(char)) - // Text may not contain these two in literal form, ยง2.4 of XML syntax - // We replace them by empty strings instead of their quoted versions because Scala XML fails the roundtrip - // Relates to https://github.com/scala/scala-xml/issues/57 - // Works around https://github.com/http4s/http4s-fs2-data/issues/88 - r = s.replace("&", "").replace("<", "") - } yield Text(r) + val genText: Gen[Text] = { + // Replace special characters with their XML entity equivalents to ensure proper roundtrip + Gen.stringOf(Gen.oneOf(char)) + .map(_.replace("&", "&").replace("<", "<")) + .map(Text(_)) + } val genComment: Gen[Comment] = for {