Force strings to UTF-8 from any encoding

前端 未结 4 1357
不知归路
不知归路 2020-12-13 13:36

In my rails app I\'m working with RSS feeds from all around the world, and some feeds have links that are not in UTF-8. The original feed links are out of my control, and i

4条回答
  •  轮回少年
    2020-12-13 13:49

    Only this solution worked for me:

    string.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
    

    Note the binary argument.

提交回复
热议问题