imathis / octopress

Octopress is an obsessively designed framework for Jekyll blogging. It’s easy to configure and easy to deploy. Sweet huh?
http://github.com/imathis/octopress
9.32k stars 2.62k forks source link

gist tag with invalid filename renders 404 Not Found GitHub page in <noscript/> tags #437

Closed roman-yepishev closed 11 years ago

roman-yepishev commented 12 years ago

STR:

  1. Create a new post with {% gist 1 invalidfilename.txt %}
  2. generate and preview the post
  3. Everything looks fine
  4. Check the page source

Actual result:

<div class="entry-content"><div><script src='https://gist.github.com/1.js?file=invalidfilename.txt'></script>
<noscript><pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head prefix=&quot;og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# githubog: http://ogp.me/ns/fb/githubog#&quot;&gt;
    &lt;meta charset='utf-8'&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
        &lt;title&gt;404 - GitHub&lt;/title&gt;

Expected result: gist conversion should fail in order not to create pages which look good in the web browser but are horribly broken in RSS feed reader.

roman-yepishev commented 12 years ago

Patch seems to be easy:

diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb
index 74dd3b3..f6ebbb3 100644
--- a/plugins/gist_tag.rb
+++ b/plugins/gist_tag.rb
@@ -82,6 +82,9 @@ module Jekyll
       https.verify_mode = OpenSSL::SSL::VERIFY_NONE
       request           = Net::HTTP::Get.new raw_uri.request_uri
       data              = https.request request
+      if data.code != 200
+          raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}"
+      end
       data              = data.body
       cache gist, file, data unless @cache_disabled
       data
parkr commented 11 years ago

Closing this in favour of your pull request.