Skip to content

Commit ea24e2a

Browse files
committed
baidu.string.decodeHTML bug fix
[bugfix] baidu.string.encodeHTML("&BaiduFE#34;"); 结果:&BaiduFE#34; baidu.string.decodeHTML("&BaiduFE#34;"); 结果:" encode后的结果decode得不到原来的值 修改了decode顺序
1 parent 28030db commit ea24e2a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/baidu/string/decodeHTML.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
* @returns {string} html解码后的字符串
2424
*/
2525
baidu.string.decodeHTML = function (source) {
26-
var str = String(source)
26+
//处理转义的中文和实体字符
27+
var str = source.replace(/&#([\d]+);/g, function(_0, _1) {
28+
return String.fromCharCode(parseInt(_1, 10));
29+
});
30+
return String(str)
2731
.replace(/"/g,'"')
2832
.replace(/&lt;/g,'<')
2933
.replace(/&gt;/g,'>')
3034
.replace(/&amp;/g, "&");
31-
//处理转义的中文和实体字符
32-
return str.replace(/&#([\d]+);/g, function(_0, _1){
33-
return String.fromCharCode(parseInt(_1, 10));
34-
});
3535
};
3636

3737
baidu.decodeHTML = baidu.string.decodeHTML;

0 commit comments

Comments
 (0)