diff --git a/partial_helper_test.go b/partial_helper_test.go index dde5932..bd808b1 100644 --- a/partial_helper_test.go +++ b/partial_helper_test.go @@ -234,6 +234,48 @@ func Test_PartialHelper_Javascript_With_HTML(t *testing.T) { r.Equal(`alert(\'\\\'Hello\\\'\');`, string(html)) } +func Test_PartialHelper_Javascript_With_HTML_Partial(t *testing.T) { + // https://github.com/gobuffalo/plush/issues/106 + r := require.New(t) + + data := map[string]interface{}{} + help := HelperContext{Context: NewContext()} + help.Set("partialFeeder", func(name string) (string, error) { + switch name { + case "js_having_html_partial.js": + return `alert('<%= partial("t1.html") %>');`, nil + case "js_having_js_partial.js": + return `alert('<%= partial("t1.js") %>');`, nil + case "t1.html": + return `
<%= partial("p1.html") %>
`, nil + case "t1.js": + return `
<%= partial("p1.js") %>
`, nil + case "p1.html", "p1.js": + return `FORM`, nil + default: + return "error", nil + } + }) + + // without content-type, js escaping is not applied + html, err := partialHelper("js_having_html_partial.js", data, help) + r.NoError(err) + r.Equal(`alert('
FORM
');`, string(html)) + + // with content-type (should be set to work properly) + help.Set("contentType", "application/javascript") + + // and including partials with js extension + html, err = partialHelper("js_having_js_partial.js", data, help) + r.NoError(err) + r.Equal(`alert('
FORM
');`, string(html)) + + // has content-type but including html extension + html, err = partialHelper("js_having_html_partial.js", data, help) + r.NoError(err) + r.Equal(`alert('\u003Cdiv\u003E\\u003Cspan\\u003EFORM\\u003C/span\\u003E\u003C/div\u003E');`, string(html)) +} + func Test_PartialHelper_Markdown(t *testing.T) { r := require.New(t) @@ -290,6 +332,38 @@ func Test_PartialHelper_Markdown_With_Layout_Reversed(t *testing.T) { r.Equal(`

This is a test

`, strings.TrimSpace(string(html))) } +func Test_PartialHelpers_Markdown_With_Nested_CodeBlock(t *testing.T) { + // for https://github.com/gobuffalo/plush/issues/82 + r := require.New(t) + + main := `<%= partial("outer.md") %>` + outer := `Some text + +<%= partial("inner.md") %> +` + inner := "```go\n" + `if true { + fmt.Println() +}` + "\n```" + + help := HelperContext{Context: NewContext()} + help.Set("contentType", "text/markdown") + help.Set("partialFeeder", func(name string) (string, error) { + if name == "outer.md" { + return outer, nil + } + return inner, nil + }) + + html, err := Render(main, help) + r.NoError(err) + r.Equal(`

Some text

+ +
if true {
+    fmt.Println()
+}
+
`, string(html)) +} + func Test_PartialHelpers_With_Indentation(t *testing.T) { r := require.New(t)