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

Array原型被污染导致渲染失败 #358

Closed
sumy7 opened this issue Mar 29, 2021 · 3 comments
Closed

Array原型被污染导致渲染失败 #358

sumy7 opened this issue Mar 29, 2021 · 3 comments

Comments

@sumy7
Copy link

sumy7 commented Mar 29, 2021

版本 v1.4.14

启动报错

Valine.min.js:formatted:2866 Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Element': '.vfunction(){this.length=0}' is not a valid selector.
    at r (http://unpkg.com/valine/dist/Valine.min.js:12:36952)
    at Array.find (http://unpkg.com/valine/dist/Valine.min.js:7:2301)
    at http://unpkg.com/valine/dist/Valine.min.js:12:19878
    at o.bind (http://unpkg.com/valine/dist/Valine.min.js:12:20016)
    at http://unpkg.com/valine/dist/Valine.min.js:12:12032
    at http://unpkg.com/valine/dist/Valine.min.js:12:23934
    at Function.sdkLoader (http://unpkg.com/valine/dist/Valine.min.js:7:4990)
    at http://unpkg.com/valine/dist/Valine.min.js:7:5059
    at HTMLScriptElement.n.onload.n.onreadystatechange (http://unpkg.com/valine/dist/Valine.min.js:7:4779)

经排查是项目中同时引入了Swiftype站内搜索,st.js库在Array原型中添加了一些方法,导致遍历失败。
以下位置for循环遍历的时候,由于Array原型被污染,导致遍历出来很多不需要的属性。

            !function(t) {
                if (t = y.default.store.get(h.MetaCacheKey) || t)
                    for (var n in p) {
                        var r = p[n];
                        e.$el.find(".v" + r).val(y.default.unescape(t[r])),
                        E[r] = t[r]
                    }
                var o = y.default.store.get(h.QQCacheKey);
                E.QQAvatar = e.config.enableQQ && !!o && o.pic || ""
            }(),

测试代码

for (let n in p) {console.log(n)}
0
1
2
clear
first
last
flatten
each
include

建议通过 hasOwnProperty 将原型中的属性过滤掉。

@xCss
Copy link
Owner

xCss commented Mar 30, 2021

收到,感谢反馈,将在下个版本修复 ~

@sumy7
Copy link
Author

sumy7 commented Mar 30, 2021

下版本发布时,还请告知一下。
在此期间,就先暂时把Swiftype功能禁用了(反正也没什么人用)。

@xCss
Copy link
Owner

xCss commented Oct 19, 2021

https://github.com/xCss/Valine/releases/tag/v1.4.15

@xCss xCss closed this as completed Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants