From 6f03cfc67c0c389437b2935ad9d4ed92f900de4d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 23 Jun 2011 16:51:03 -0500 Subject: [PATCH] Assume utf8 when serving raw text blobs --- lib/linguist/pathname.rb | 2 +- test/test_blob.rb | 16 ++++++++-------- test/test_pathname.rb | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/linguist/pathname.rb b/lib/linguist/pathname.rb index 00a10f66..d9e6059d 100644 --- a/lib/linguist/pathname.rb +++ b/lib/linguist/pathname.rb @@ -87,7 +87,7 @@ module Linguist # # Returns a content type String. def content_type - @content_type ||= binary? ? mime_type : 'text/plain' + @content_type ||= binary? ? mime_type : 'text/plain; charset=utf8' end # Public: Is the path binary? diff --git a/test/test_blob.rb b/test/test_blob.rb index 6cc8511f..19eb69a9 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -35,14 +35,14 @@ class TestBlob < Test::Unit::TestCase assert_equal "application/octet-stream", blob("dog.o").content_type assert_equal "application/pdf", blob("foo.pdf").content_type assert_equal "image/png", blob("foo.png").content_type - assert_equal "text/plain", blob("README").content_type - assert_equal "text/plain", blob("foo.html").content_type - assert_equal "text/plain", blob("foo.pl").content_type - assert_equal "text/plain", blob("foo.py").content_type - assert_equal "text/plain", blob("foo.rb").content_type - assert_equal "text/plain", blob("foo.sh").content_type - assert_equal "text/plain", blob("foo.xhtml").content_type - assert_equal "text/plain", blob("foo.xml").content_type + assert_equal "text/plain; charset=utf8", blob("README").content_type + assert_equal "text/plain; charset=utf8", blob("foo.html").content_type + assert_equal "text/plain; charset=utf8", blob("foo.pl").content_type + assert_equal "text/plain; charset=utf8", blob("foo.py").content_type + assert_equal "text/plain; charset=utf8", blob("foo.rb").content_type + assert_equal "text/plain; charset=utf8", blob("foo.sh").content_type + assert_equal "text/plain; charset=utf8", blob("foo.xhtml").content_type + assert_equal "text/plain; charset=utf8", blob("foo.xml").content_type end def test_disposition diff --git a/test/test_pathname.rb b/test/test_pathname.rb index 520a6d38..8bc65fc2 100644 --- a/test/test_pathname.rb +++ b/test/test_pathname.rb @@ -58,8 +58,8 @@ class TestPathname < Test::Unit::TestCase end def test_content_type - assert_equal 'text/plain', Pathname.new("file.txt").content_type - assert_equal 'text/plain', Pathname.new("file.rb").content_type + assert_equal 'text/plain; charset=utf8', Pathname.new("file.txt").content_type + assert_equal 'text/plain; charset=utf8', Pathname.new("file.rb").content_type assert_equal 'image/png', Pathname.new("octocat.png").content_type end end