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

getComputedStyle 会将JSON数据的反斜杠去掉 #1

Closed
jas0ncn opened this issue May 8, 2016 · 1 comment
Closed

getComputedStyle 会将JSON数据的反斜杠去掉 #1

jas0ncn opened this issue May 8, 2016 · 1 comment

Comments

@jas0ncn
Copy link

jas0ncn commented May 8, 2016

早上看到了CSST就来试了试

刚刚按照作者思路看了一下,自己测试的时候发现如果 css 中的 content 是JSON编码数据,也就是带有反斜杠的,getComputedStyle 出来的数据中,反斜杠会被去掉。

测试api:http://szukx.sinaapp.com/api/testcsst.php?id=1&text=%E4%B8%AD%E5%9B%BD

测试代码:

csst('http://szukx.sinaapp.com/api/testcsst.php?id=1&text=%E4%B8%AD%E5%9B%BD', function(err, text) {
    console.log(text)
});

控制台的结果:

u4e2du56fd

正常应该是

\u4e2d\u56fd

想问问作者有什么办法解决的吗?
总不能把u前面手动加个反斜杠把。

@zswang
Copy link
Owner

zswang commented May 8, 2016

CSS 中的字符串也需要转义,不过是另一套转义规则
参考:http://stackoverflow.com/questions/10393462/placing-unicode-character-in-css-content-value

可以这样考虑:

#__csst1 {
  content: "\4e2d\56fd";
}
#__csst2 {
  content: "\\u4e2d\\u56fd";
}

传输 base64 字符串也是一种方案。

感谢反馈。

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

2 participants