package postcard
import (
"context"
"errors"
"strings"
"testing"
)
// schemeFiller surrounds a case's markup, so a snippet that points at the
// offending markup is told apart from one that starts the document.
var schemeFiller = strings.Repeat("plain words here ", 6)
// TestURLSchemeCheck covers the anchored, decoded URL-scheme check of
// rendered HTML (WR-05): prose and URLs that merely contain a scheme word
// pass; every URL-bearing attribute, CSS, meta refresh and every
// character-reference or whitespace-split spelling of a script or data URL
// is refused, on a send with inlining on and off and in the editor.
func TestURLSchemeCheck(t *testing.T) {
t.Parallel()
accepts := []struct{ name, html string }{
{"prose_metadata", `
See the metadata: field
`},
{"prose_big_data", `
Big Data: Summit
`},
{"img_alt", ``},
{"title_text", `
Tips
`},
{"scheme_in_query", `x`},
// Escaped markup in a raw-text element is text to every reader.
{"textarea_escaped_link", ``},
{"title_escaped_link", ``},
{"noscript_safe_link", ``},
// Text shaped like an event handler is text (WR-02).
{"prose_handler_shaped", `
`, `onclick="x()"`, "event handlers"},
{"handler_without_space", ``, `onerror="alert(1)"`, "event handlers"},
// Raw-text element content that a mail client parses as markup
// (scripting off, foreign content in svg) (CR-02).
{"noscript_href", ``, `href="javascript:alert(1)"`, schemeMsg},
{"noscript_handler", ``, `onerror=alert(1)`, "event handlers"},
{"svg_title_href", ``, `href="javascript:alert(1)"`, schemeMsg},
{"svg_textarea_href", ``, `href="javascript:alert(1)"`, schemeMsg},
{"svg_style_entity", ``, `javascript:alert(1)`, schemeMsg},
{"xmp_href", `x`, `href="javascript:alert(1)"`, schemeMsg},
{"self_closing_style", `x`, `javascript:alert(1)`, schemeMsg},
{"conditional_comment_handler", ``, `onerror="alert(1)"`, "event handlers"},
// An end tag inside a quoted attribute ends the raw-text element for
// the tokenizer but not for a conforming parser, which keeps the
// rest of the tag together (CR-02 residual).
{"svg_style_end_in_attr", ``, `href="javascript:alert(1)"`, schemeMsg},
// Whitespace-split schemes in list, meta, CSS and comment values
// (WR-01).
{"values_tab_split", ``, `values="java script:alert(1)"`, schemeMsg},
{"meta_refresh_tab_split", ``, `url=java script:alert(1)`, schemeMsg},
{"srcset_newline_split", ``, `java
script:x 2x`, schemeMsg},
{"style_tab_split", `