Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

fix(sim): anchor office-id pattern with \z so trailing newlines are rejected

eyalgolan51ad97e3d887
diff --git a/sim/Statecraft.Sim.Tests/OfficesTests.cs b/sim/Statecraft.Sim.Tests/OfficesTests.cs
index 23f675de1..3becfe991 100644
--- a/sim/Statecraft.Sim.Tests/OfficesTests.cs
+++ b/sim/Statecraft.Sim.Tests/OfficesTests.cs
@@ -52,6 +52,15 @@ public class OfficesTests
Assert.Equal($"offices[{id}].id", ex.Field);
}
+ [Fact]
+ public void OfficeIdWithTrailingNewlineIsRejected()
+ {
+ var offices = Fixture.Files["offices.yaml"] + " - id: \"minister\\n\"\n title: Bad\n";
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new System.Collections.Generic.Dictionary<string, string> { ["offices.yaml"] = offices })));
+ Assert.Equal("offices.yaml", ex.File);
+ Assert.Equal("offices[minister\n].id", ex.Field);
+ }
+
[Fact]
public void UnfilledPlaceholderThrows() =>
Assert.Throws<InvalidOperationException>(() => Offices.Fill(C, "{prime_minister}", new DateTime(1947, 1, 1)));
diff --git a/sim/Statecraft.Sim/Offices.cs b/sim/Statecraft.Sim/Offices.cs
index 454a37e52..f41b5d370 100644
--- a/sim/Statecraft.Sim/Offices.cs
+++ b/sim/Statecraft.Sim/Offices.cs
@@ -20,7 +20,7 @@ namespace Statecraft.Sim
internal static readonly Regex Placeholder = new Regex(@"\{([a-z0-9_]+)\}");
- internal static readonly Regex OfficeId = new Regex(@"^[a-z][a-z0-9_]*$");
+ internal static readonly Regex OfficeId = new Regex(@"^[a-z][a-z0-9_]*\z");
/// <summary>Replaces {office_id} with the name of the person holding it on date.</summary>
public static string Fill(Content c, string text, DateTime date) =>