Skip to content

Prevent "unknown encoding: ASCII-8BIT" errors #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2015

Conversation

kaspth
Copy link
Contributor

@kaspth kaspth commented Mar 4, 2015

Fixes #30

Nokogiri would throw these errors when outputting the fragment with #to_s.
Instead call the format serializers directly and pass a UTF-8 encoding.

cc @rafaelfranca @kindjar @ncri @Junichilto

@@ -136,6 +136,10 @@ def allowed_tags(options)
def allowed_attributes(options)
options[:attributes] || self.class.allowed_attributes
end

def properly_encode(fragment, options)
fragment.xml? ? fragment.to_xml(options) : fragment.to_html(options)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how likely it is to sanitize an XML document, but I added it for completeness.

Nokogiri would throw these errors when outputting the fragment with #to_s.
Instead call the format serializers directly and pass a UTF-8 encoding.
@kaspth kaspth force-pushed the accept-ascii-8bit-strings branch from f3d1e7b to 2362298 Compare March 4, 2015 21:07
@kindjar
Copy link

kindjar commented Mar 4, 2015

👍 This change sanitizes without errors given strings from either the newer mysql2 or the older mysql gem (verified in the older version of my app that was having issues).

@kaspth
Copy link
Contributor Author

kaspth commented Mar 4, 2015

@kindjar Great to hear 😉

kaspth added a commit that referenced this pull request Mar 6, 2015
Prevent "unknown encoding: ASCII-8BIT" errors
@kaspth kaspth merged commit 670fd7a into master Mar 6, 2015
@kaspth kaspth deleted the accept-ascii-8bit-strings branch March 6, 2015 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encoding errors on ASCII-8BIT strings (eg: any string from the mysql adapter)
3 participants