Keep generated prose out of Markdown structure
This commit is contained in:
@@ -627,6 +627,36 @@ func TestBuildDailyRenderContext(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestValidatedGeneratedTextRendersAsPlainText(t *testing.T) {
|
||||
generated, _, err := ValidateDaily([]byte("{\"summary\":\"Summary.\\n## Fabricated Alert\\n- Fabricated warning\",\"forecast_discussion\":[\"Discussion with [unsafe](javascript:alert(1))\"],\"precipitation_timing\":\"Timing.\\n```not code```\"}"))
|
||||
if err != nil {
|
||||
t.Fatalf("ValidateDaily() error = %v", err)
|
||||
}
|
||||
context, err := BuildDailyRenderContext(testDailyMetadata(), testDailySnapshot(t), generated, testDailyDerived())
|
||||
if err != nil {
|
||||
t.Fatalf("BuildDailyRenderContext() error = %v", err)
|
||||
}
|
||||
rendered, err := reporttemplate.Render("daily", context)
|
||||
if err != nil {
|
||||
t.Fatalf("Render() error = %v", err)
|
||||
}
|
||||
text := string(rendered)
|
||||
for _, want := range []string{
|
||||
"Summary.\n\\## Fabricated Alert\n\\- Fabricated warning",
|
||||
"Discussion with \\[unsafe\\]\\(javascript:alert\\(1\\)\\)",
|
||||
"Timing.\n\\`\\`\\`not code\\`\\`\\`",
|
||||
} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Fatalf("rendered report missing escaped generated prose %q:\n%s", want, text)
|
||||
}
|
||||
}
|
||||
for _, unwanted := range []string{"\n## Fabricated Alert", "\n- Fabricated warning", "[unsafe](javascript:alert(1))", "```not code```"} {
|
||||
if strings.Contains(text, unwanted) {
|
||||
t.Fatalf("rendered report preserved generated Markdown structure %q:\n%s", unwanted, text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildDailyRenderContextAllowsOmittedOptionalModules(t *testing.T) {
|
||||
snapshot, err := module.NewSnapshot(nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user