Path: redb-route/tests/redb.Route.Tests/Expressions/XmlEntityExpansionTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests/Expressions/XmlEntityExpansionTests.cs ---- using System.Text; using AwesomeAssertions; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Expressions; namespace redb.Route.Tests.Expressions; /// /// A message body is somebody else's XML, whatever transport carried it. Evaluating an XPath over one /// used to parse it with the expanding loader, so a 452-byte body with nested internal entities cost /// the worker hundreds of thousands of characters — and that is the small version. Reported while /// preparing the AS4 connector, 2026-09-25. /// public class XmlEntityExpansionTests { private static string BillionLaughs(int levels = 5, int fanOut = 10) { var sb = new StringBuilder(""); for (var i = 1; i <= levels; i++) { sb.Append($""); } return sb.Append($"]>&lol{levels};").ToString(); } private static IExchange WithBody(object body) => new Exchange(new Message(body)); [Fact] public void An_xpath_over_a_body_with_a_dtd_is_refused_not_expanded() { var exchange = WithBody(BillionLaughs()); var act = () => new XPathExpression("/lolz").Evaluate(exchange); // Refused, and refused loudly: a route that cannot read the body must not quietly carry on // with an empty value either. act.Should().Throw().Which.ToString().Should().Contain("DTD"); } [Fact] public void An_ordinary_xml_body_still_evaluates() { var exchange = WithBody("7"); new XPathExpression("/order/id").Evaluate(exchange).Should().Be("7"); } }