Skip to content

Fix encoding error for gist_tag #23

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 3 commits into from
Oct 24, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/jekyll-gist/gist_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Gist
class GistTag < Liquid::Tag

def render(context)
@encoding = context.registers[:site].config['encoding']
if tag_contents = determine_arguments(@markup.strip)
gist_id, filename = tag_contents[0], tag_contents[1]
if context.has_key?(gist_id)
Expand Down Expand Up @@ -69,7 +70,7 @@ def fetch_raw_code(gist_id, filename = nil)
read_timeout: 3, open_timeout: 3) do |http|
request = Net::HTTP::Get.new uri.to_s
response = http.request(request)
response.body
response.body.force_encoding(@encoding)
Copy link
Member

Choose a reason for hiding this comment

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

I think GitHub always sends back UTF-8. Maybe @benbalter can help with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps, but if the Jekyll user sets their site to use something else, and jekyll-gist returns utf-8, is Liquid not going to error out as it is now, with the mix of utf-8 and ascii 8bit?

end
rescue SocketError, Net::HTTPError, Net::OpenTimeout, Net::ReadTimeout, TimeoutError
nil
Expand Down