diff --git a/lib/rocco.rb b/lib/rocco.rb index 7abda79..ec62b39 100644 --- a/lib/rocco.rb +++ b/lib/rocco.rb @@ -194,7 +194,7 @@ class Rocco # then fork off a child process to write the input. def highlight_pygmentize(code) code_html = nil - open("|pygmentize -l #{@options[:language]} -f html", 'r+') do |fd| + open("|pygmentize -l #{@options[:language]} -O encoding=utf-8 -f html", 'r+') do |fd| pid = fork { fd.close_read diff --git a/test/fixtures/issue10.iso-8859-1.rb b/test/fixtures/issue10.iso-8859-1.rb new file mode 100644 index 0000000..34d1a80 --- /dev/null +++ b/test/fixtures/issue10.iso-8859-1.rb @@ -0,0 +1 @@ +# hello wörld diff --git a/test/fixtures/issue10.rb b/test/fixtures/issue10.rb deleted file mode 100644 index 93e2940..0000000 --- a/test/fixtures/issue10.rb +++ /dev/null @@ -1 +0,0 @@ -hello ąćęłńóśźż diff --git a/test/fixtures/issue10.utf-8.rb b/test/fixtures/issue10.utf-8.rb new file mode 100644 index 0000000..e87e125 --- /dev/null +++ b/test/fixtures/issue10.utf-8.rb @@ -0,0 +1 @@ +# hello ąćęłńóśźż diff --git a/test/rocco_test.rb b/test/rocco_test.rb index ff86ed8..58c0820 100644 --- a/test/rocco_test.rb +++ b/test/rocco_test.rb @@ -101,10 +101,20 @@ class RoccoIssueTests < Test::Unit::TestCase def test_issue10_utf8_processing # Rocco has issues with strange UTF-8 characters: need to explicitly set the encoding for Pygments # http://github.com/rtomayko/rocco/issues#issue/10 - r = Rocco.new( File.dirname(__FILE__) + "/fixtures/issue10.rb" ) + r = Rocco.new( File.dirname(__FILE__) + "/fixtures/issue10.utf-8.rb" ) assert_equal( - "

hello ąćęłńóśźż

\n", - r.sections[0][0] + "

hello ąćęłńóśźż

\n", + r.sections[0][0], + "UTF-8 input files ought behave correctly." + ) + # and, just for grins, ensure that iso-8859-1 works too. + # @TODO: Is this really the correct behavior? Converting text + # to UTF-8 on the way out is probably preferable. + r = Rocco.new( File.dirname(__FILE__) + "/fixtures/issue10.iso-8859-1.rb" ) + assert_equal( + "

hello w\366rld

\n", + r.sections[0][0], + "ISO-8859-1 input should probably also behave correctly." ) end def test_issue12_css_octothorpe_classname_change