mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
11e4e67599
Previously, there were a few places where the compiler would create strings from template content and emit them as template literals, but didn't properly escape characters or character sequences with special meanings, in particular: backslashes, backticks, and interpolation sigils. This commit fixes this in: - block creation (interpolation sigils were not escaped) - text node creation (no escaping was performed) - comment not creation (no escaping was performed) - default values for t-esc (no escaping was performed) - body of a t-set (no escaping was performed)
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { renderToString, snapshotEverything } from "../helpers";
|
|
|
|
snapshotEverything();
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// comments
|
|
// -----------------------------------------------------------------------------
|
|
|
|
describe("comments", () => {
|
|
test("properly handle comments", () => {
|
|
const template = `<div>hello <!-- comment-->owl</div>`;
|
|
expect(renderToString(template)).toBe("<div>hello <!-- comment-->owl</div>");
|
|
});
|
|
|
|
test("only a comment", () => {
|
|
const template = `<!-- comment-->`;
|
|
expect(renderToString(template)).toBe(`<!-- comment-->`);
|
|
});
|
|
|
|
test("properly handle comments between t-if/t-else", () => {
|
|
const template = `
|
|
<div>
|
|
<span t-if="true">true</span>
|
|
<!-- comment-->
|
|
<span t-else="">owl</span>
|
|
</div>`;
|
|
expect(renderToString(template)).toBe("<div><span>true</span></div>");
|
|
});
|
|
|
|
test("comment node with backslash at top level", () => {
|
|
const template = "<!-- \\ -->";
|
|
expect(renderToString(template)).toBe("<!-- \\ -->");
|
|
});
|
|
|
|
test("comment node with backtick at top-level", () => {
|
|
const template = "<!-- ` -->";
|
|
expect(renderToString(template)).toBe("<!-- ` -->");
|
|
});
|
|
|
|
test("comment node with interpolation sigil at top level", () => {
|
|
const template = "<!-- ${very cool} -->";
|
|
expect(renderToString(template)).toBe("<!-- ${very cool} -->");
|
|
});
|
|
});
|