mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] can use t-out with String classes
This commit is contained in:
committed by
Samuel Degueldre
parent
554157637b
commit
5940048a19
@@ -135,7 +135,7 @@ export function safeOutput(value: any): ReturnType<typeof toggler> {
|
||||
} else if (value instanceof LazyValue) {
|
||||
safeKey = `lazy_value`;
|
||||
block = value.evaluate();
|
||||
} else if (typeof value === "string") {
|
||||
} else if (value instanceof String || typeof value === "string") {
|
||||
safeKey = "string_unsafe";
|
||||
block = text(value);
|
||||
} else {
|
||||
|
||||
@@ -9,11 +9,11 @@ const characterDataSetData = getDescriptor(characterDataProto, "data").set!;
|
||||
const nodeRemoveChild = nodeProto.removeChild;
|
||||
|
||||
abstract class VSimpleNode {
|
||||
text: string;
|
||||
text: string | String;
|
||||
parentEl?: HTMLElement | undefined;
|
||||
el?: any;
|
||||
|
||||
constructor(text: string) {
|
||||
constructor(text: string | String) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class VComment extends VSimpleNode {
|
||||
patch() {}
|
||||
}
|
||||
|
||||
export function text(str: string): VNode<VText> {
|
||||
export function text(str: string | String): VNode<VText> {
|
||||
return new VText(str);
|
||||
}
|
||||
|
||||
|
||||
@@ -407,6 +407,36 @@ exports[`t-out variable 1`] = `
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`t-out with a String class 1`] = `
|
||||
"function anonymous(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 = \\"\\") {
|
||||
let b2 = safeOutput(ctx['var']);
|
||||
return block1([], [b2]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`t-out with an extended String class 1`] = `
|
||||
"function anonymous(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 = \\"\\") {
|
||||
let b2 = safeOutput(ctx['var']);
|
||||
return block1([], [b2]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`t-raw is deprecated should warn 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -37,6 +37,26 @@ describe("t-out", () => {
|
||||
expect(renderToString(template, { var: "ok" })).toBe("<span>ok</span>");
|
||||
});
|
||||
|
||||
test("with a String class", () => {
|
||||
const template = `<span><t t-out="var"/></span>`;
|
||||
expect(renderToString(template, { var: new String("ok") })).toBe("<span>ok</span>");
|
||||
});
|
||||
|
||||
test("with an extended String class", () => {
|
||||
class LoveString extends String {
|
||||
valueOf(): string {
|
||||
return `<3 ${super.valueOf()} <3`;
|
||||
}
|
||||
toString(): string {
|
||||
return this.valueOf();
|
||||
}
|
||||
}
|
||||
const template = `<span><t t-out="var"/></span>`;
|
||||
expect(renderToString(template, { var: new LoveString("ok") })).toBe(
|
||||
"<span><3 ok <3</span>"
|
||||
);
|
||||
});
|
||||
|
||||
test("not escaping", () => {
|
||||
const template = `<div><t t-out="var"/></div>`;
|
||||
expect(renderToString(template, { var: markup("<ok></ok>") })).toBe("<div><ok></ok></div>");
|
||||
|
||||
Reference in New Issue
Block a user