Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mip-mustache.js 的sanitizer会把script type="application/json"过滤掉 #1177

Open
jennyliang220 opened this issue Jun 6, 2018 · 0 comments
Assignees

Comments

@jennyliang220
Copy link
Member

使用场景

使用mustache渲染以下模板:

<template type="mip-mustache">
    {{#mip-ad-group}}
        <h1>实验组A: 渲染网盟广告</h1>
        <mip-ad
            type="ad-baidu" 
            cproid="u2697398">
        </mip-ad>
    {{/mip-ad-group}}
    {{#mip-ad-ecom-group}}
        <h1>实验组B: 渲染凤巢广告</h1>
        <mip-ad-ecom layout="fixed-height" height="343" id="mip-ad-ecom">
        <script type="application/json" for="mip-ad-ecom">
            {
                "accid": "e2217bab684fbb898dccf04b",
                "title": "%E8%BF%99%E9%87%8C%E6%98%AF%E6%A0%87%E9%A2%98"
            }
        </script>
        </mip-ad-ecom>
    {{/mip-ad-ecom-group}}
</template>

当数据中mip-ad-ecom-group == true,渲染产出为

<h1>实验组B: 渲染凤巢广告</h1>
<mip-ad-ecom layout="fixed-height" height="343" id="mip-ad-ecom">
        <script type="application/json" for="mip-ad-ecom">
            {
                "accid": "e2217bab684fbb898dccf04b",
                "title": "%E8%BF%99%E9%87%8C%E6%98%AF%E6%A0%87%E9%A2%98"
            }
        </script>
</mip-ad-ecom>

但是经过sanitizer.js(压缩版,没注释)处理之后,

Mustache.prototype.render = function (templateHTML, data) {
var html = mustache.render(templateHTML, data);
return sanitizer(html);
};

产出变成了:

<h1>实验组B: 渲染凤巢广告</h1>
<mip-ad-ecom layout="fixed-height" height="343" id="mip-ad-ecom">
</mip-ad-ecom>

配置丢失了!!

目前比较挫的解决办法

把配置写在template外面,在需要配置的组件中全局查找。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant