puppet-wechat icon indicating copy to clipboard operation
puppet-wechat copied to clipboard

处理会话列表/昵称里的Emoji符号有问题

Open ouch1985 opened this issue 5 years ago • 2 comments

问题: 昵称里有Emoji符号,解析出来会有乱码,比如我一个群聊的房间名称叫 "机器人群💪" 💪会解析出来乱码

问题出在 pure-function-helpers/xml.js 的 function digestEmoji(html) { if (!html) { return ''; } return html .replace(/<img class="(\w*?emoji) (\w*?emoji[^"]+?)" text="(.?)_web" src=[^>]+>/g, '$3') // .replace(/<span class="(\w?emoji) (\w*?emoji[^"]+?)"></span>/g, '[$2]'); // '' }

我手工改一下暂时可以用,改成 function emojiCode2string(txt){ try{ return txt ? String.fromCodePoint(0x${txt.replace('emoji', '')}) : ''; }catch(e){ return ''; } }

function digestEmoji(html) { if (!html) { return ''; } return html .replace(/<img class="(\w*?emoji) (\w*?emoji[^"]+?)" text="(.?)_web" src=[^>]+>/g, function(input, $1, $2){ return emojiCode2string($2); }) // .replace(/<span class="(\w?emoji) (\w*?emoji[^"]+?)"></span>/g, '[$2]'); // '' }

使用 String.fromCodePoint(xxxx) 来处理,emoji编码从img标签的 class name里取

ouch1985 avatar Feb 11 '20 08:02 ouch1985

Thanks for reporting and share your code about this.

Would you like to send your code as a Pull Request to fix your issue?

If you do, please also remember to add a unit test to make sure your code is working as expected.

huan avatar Feb 11 '20 08:02 huan

不好意思,我对github这一套流程还不是很熟悉。源码是ts写的,我还不熟悉,怕再改出其他问题了,方便的话,还是你们来修复一下吧

ouch1985 avatar Feb 11 '20 08:02 ouch1985