收藏
回答

String contained an illegal UTF-16 sequence,这是什么错?

回答关注问题邀请回答
收藏

2 个回答

  • 🌞
    🌞
    2022-07-28

    过滤非法字符

    const replacement = '\ufffd';
    // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
    const loneSurrogates = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|([^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
     
    // string sanitizes the given str by replacing invalid UTF-16 code unit
    // sequences with the unicode replacement character. Returns a new string.
    //用 \ufffd 取代无效的增补字节的,无效的高位或者低位
    exports.string = function(str) {
        return str.replace(loneSurrogates, '$1' + replacement);
    }
    
    2022-07-28
    有用 1
    回复
  • 白宦成 #Linux中国
    白宦成 #Linux中国
    2020-03-02

    字符串中包含了一个非标准的 UTF-16 字符

    2020-03-02
    有用
    回复 2
    • 禾店科技
      禾店科技
      2021-04-28
      是的
      2021-04-28
      回复
    • shystar
      shystar
      2021-12-24
      这个有什么好的解决方案吗?有些会出现页面无法打开。
      2021-12-24
      回复
登录 后发表内容
问题标签