Coder Social home page Coder Social logo

Comments (3)

jsocol avatar jsocol commented on June 9, 2024

Honestly I don't think this is Bleach's responsibility. Do you have a use case where the app using Bleach doesn't know the incoming text charset?

I guess I'd call this a documentation issue and say if you know you're going to be passing in a bytestring with non-ASCII characters, convert it to a unicode object first.

from bleach.

markmcclain avatar markmcclain commented on June 9, 2024

Calling this a documentation issue is a reasonable resolution. This line should be changed:

"NB: Bleach accepts bytestrings or unicode, but it always returns unicode."

To me, it implies that bleach is going to attempt to do the right thing when converting to unicode. Maybe something similar to this:

NB: Given a bytestring or unicode, Bleach will always return unicode; however, the conversion from bytestring to unicode does not respect character encoding. If you are using a specific encoding, please convert the bytestring to unicode before using Bleach to ensure document integrity.

from bleach.

jsocol avatar jsocol commented on June 9, 2024

Updated the README, and I also added an explicit cast to UTF8 for bytestrings, so your original example should just work now (as opposed to the implicit bytestring->unicode conversion that was happening). This makes clean() more consistent with linkify().

It would be relatively easy to add an encoding='utf-8' kwarg to both clean() and linkify(), that would be passed along to force_unicode(). Bleach still wouldn't do charset detection but you wouldn't need to do the decode() yourself.

from bleach.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.