From 063a8ca5a751e75b08f96765d521aa29994c5211 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Tue, 1 Dec 2009 21:29:07 -0600 Subject: [PATCH] Fix Maruku Ruby 1.9 Bug In Rbuy 1.8, ?c returns an integer. In Ruby 1.9, it returns a 1-character string. This was causing one of our LaTeX conversion functional tests to fail. Fixed. --- test/functional/wiki_controller_test.rb | 17 +++++++++++++++++ .../lib/maruku/output/to_latex_strings.rb | 10 +++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index de43c267..3d0ce78c 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -1263,6 +1263,23 @@ HisWay would be MyWay $\sin(x) \includegraphics[width=3em]{foo}$ in kinda ThatWa +\end{document} +!, r.body + end + + def test_tex_character_conversions + @wiki.write_page('wiki1', 'Page2', + "Page2 contents { & ^ <.\n", + Time.now, Author.new('AnotherAuthor', '127.0.0.2'), x_test_renderer) + r = process('tex', 'web' => 'wiki1', 'id' => 'Page2') + assert_response(:success) + + assert_equal @tex_header1 + @tex_header2 + %q!\section*{Page2} + +Page2 contents \{ \& {\tt \symbol{94}} {\tt \symbol{60}}. + + + \end{document} !, r.body end diff --git a/vendor/plugins/maruku/lib/maruku/output/to_latex_strings.rb b/vendor/plugins/maruku/lib/maruku/output/to_latex_strings.rb index da043a79..ab54ba43 100644 --- a/vendor/plugins/maruku/lib/maruku/output/to_latex_strings.rb +++ b/vendor/plugins/maruku/lib/maruku/output/to_latex_strings.rb @@ -23,19 +23,19 @@ class String # These are TeX's special characters - LATEX_ADD_SLASH = [ ?{, ?}, ?$, ?&, ?#, ?_, ?%] + LATEX_ADD_SLASH = [ '{', '}', '$', '&', '#', '_', '%'] # These, we transform to {\tt \char} - LATEX_TO_CHARCODE = [ ?^, ?~, ?>,?<] + LATEX_TO_CHARCODE = [ '^', '~', '>', '<'] def escape_to_latex(s) s2 = "" - s.each_byte do |b| + s.each_char do |b| if LATEX_TO_CHARCODE.include? b - s2 += "{\\tt \\char#{b}}" + s2 += "{\\tt \\symbol{#{b.ord}}}" elsif LATEX_ADD_SLASH.include? b s2 << ?\\ << b - elsif b == ?\\ + elsif b == '\\' # there is no backslash in cmr10 fonts s2 += "$\\backslash$" else