mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] t-out: allow expressions evaluating as number
This commit is contained in:
committed by
Sam Degueldre
parent
1fc88f626f
commit
a3111eb9ca
@@ -132,19 +132,30 @@ export function safeOutput(value: any): ReturnType<typeof toggler> {
|
|||||||
}
|
}
|
||||||
let safeKey;
|
let safeKey;
|
||||||
let block;
|
let block;
|
||||||
if (value instanceof Markup) {
|
switch (typeof value) {
|
||||||
safeKey = `string_safe`;
|
case "object":
|
||||||
block = html(value as string);
|
if (value instanceof Markup) {
|
||||||
} else if (value instanceof LazyValue) {
|
safeKey = `string_safe`;
|
||||||
safeKey = `lazy_value`;
|
block = html(value as string);
|
||||||
block = value.evaluate();
|
} else if (value instanceof LazyValue) {
|
||||||
} else if (value instanceof String || typeof value === "string") {
|
safeKey = `lazy_value`;
|
||||||
safeKey = "string_unsafe";
|
block = value.evaluate();
|
||||||
block = text(value);
|
} else if (value instanceof String) {
|
||||||
} else {
|
safeKey = "string_unsafe";
|
||||||
// Assuming it is a block
|
block = text(value);
|
||||||
safeKey = "block_safe";
|
} else {
|
||||||
block = value;
|
// 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);
|
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`] = `
|
exports[`t-out t-out 0 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ describe("t-out", () => {
|
|||||||
expect(renderToString(template)).toBe("<span>ok</span>");
|
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", () => {
|
test("literal, no outside html element", () => {
|
||||||
const template = `<t t-out="'ok'"/>`;
|
const template = `<t t-out="'ok'"/>`;
|
||||||
expect(renderToString(template)).toBe("ok");
|
expect(renderToString(template)).toBe("ok");
|
||||||
|
|||||||
Reference in New Issue
Block a user