[FIX] t-out: allow expressions evaluating as number

This commit is contained in:
Géry Debongnie
2022-06-07 10:33:59 +02:00
committed by Sam Degueldre
parent 1fc88f626f
commit a3111eb9ca
3 changed files with 44 additions and 13 deletions
+24 -13
View File
@@ -132,19 +132,30 @@ export function safeOutput(value: any): ReturnType<typeof toggler> {
}
let safeKey;
let block;
if (value instanceof Markup) {
safeKey = `string_safe`;
block = html(value as string);
} else if (value instanceof LazyValue) {
safeKey = `lazy_value`;
block = value.evaluate();
} else if (value instanceof String || typeof value === "string") {
safeKey = "string_unsafe";
block = text(value);
} else {
// Assuming it is a block
safeKey = "block_safe";
block = value;
switch (typeof value) {
case "object":
if (value instanceof Markup) {
safeKey = `string_safe`;
block = html(value as string);
} else if (value instanceof LazyValue) {
safeKey = `lazy_value`;
block = value.evaluate();
} else if (value instanceof String) {
safeKey = "string_unsafe";
block = text(value);
} else {
// Assuming it is a block
safeKey = "block_safe";
block = value;
}
break;
case "string":
safeKey = "string_unsafe";
block = text(value);
break;
default:
safeKey = "string_unsafe";
block = text(String(value));
}
return toggler(safeKey, block);
}
@@ -79,6 +79,21 @@ exports[`t-out not escaping 1`] = `
}"
`;
exports[`t-out number literal 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
let { safeOutput } = helpers;
let block1 = createBlock(\`<span><block-child-0/></span>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = safeOutput(1);
return block1([], [b2]);
}
}"
`;
exports[`t-out t-out 0 1`] = `
"function anonymous(app, bdom, helpers
) {
+5
View File
@@ -27,6 +27,11 @@ describe("t-out", () => {
expect(renderToString(template)).toBe("<span>ok</span>");
});
test("number literal", () => {
const template = `<span><t t-out="1"/></span>`;
expect(renderToString(template)).toBe("<span>1</span>");
});
test("literal, no outside html element", () => {
const template = `<t t-out="'ok'"/>`;
expect(renderToString(template)).toBe("ok");