Skip to content
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

Encoding Error #893

Closed
mikem836 opened this issue Mar 17, 2020 · 6 comments · Fixed by #894
Closed

Encoding Error #893

mikem836 opened this issue Mar 17, 2020 · 6 comments · Fixed by #894

Comments

@mikem836
Copy link
Contributor

Issue description

With version 2.0.1, when I try to render a PDF that has any UTF characters, I get the error from Rails: Encoding::CompatibilityError "incompatible character encodings: ASCII-8BIT and UTF-8" It appears that PR #864 removed UTF-8 encoding when changed from using open-uri to net/http.

Expected or desired behavior

No error. The same PDF can be rendered without error on wicked_pdf 2.0.0

System specifications

wicked_pdf gem version (output of cat Gemfile.lock | grep wicked_pdf): 2.0.1

wkhtmltopdf version (output of wkhtmltopdf --version): 0.12.5

whtmltopdf provider gem and version if one is used: tested both wkhtmltopdf-binary-edge v0.12.5.1 and wkhtmltopdf-heroku v2.12.5.0

platform/distribution and version (e.g. Windows 10 / Ubuntu 16.04 / Heroku cedar): Heroku 18

@unixmonkey
Copy link
Collaborator

unixmonkey commented Mar 17, 2020

Does monkeypatching read_from_uri to force encoding to UTF fix your issue?
Drop this in a file in config/initializers/ and let me know if it helps and I'll create a fix.

class WickedPdf
  module WickedPdfHelper
    module Assets
      private
      
      def read_from_uri(uri)
        asset = Net::HTTP.get(URI(uri))
        asset.force_encoding('UTF-8') if asset # <- new line added
        asset = gzip(asset) if WickedPdf.config[:expect_gzipped_remote_assets]
        asset
      end
    end
  end
end

@mikem836
Copy link
Contributor Author

Yes that fixes it. I had tried similar in a branch I created https://github.com/mikem836/wicked_pdf/tree/encoding but wasn't confident enough in the general applicability of the fix to do a PR.

@unixmonkey
Copy link
Collaborator

Sweet. Would you mind making a PR with this change and a related note in the CHANGELOG?

@mikem836
Copy link
Contributor Author

Will do. I did want to add a test also, but haven't been able to get the tests running locally.

@unixmonkey
Copy link
Collaborator

What kind of issue are you running into running the tests?
If you create a PR, tests should automatically run on TravisCI.

@mikem836
Copy link
Contributor Author

Yes, I created the PR and everything ran on TravisCI. I just haven't been able to run them locally. I think some kind of path issue in my local environment.

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 a pull request may close this issue.

2 participants