spring-io / spring-asciidoctor-backends

A backend for Asciidoctor used to produce Spring styled HTML
Apache License 2.0
77 stars 15 forks source link

Encoding problems in Maven builds that copy resources as UTF-8 #80

Closed wilkinsona closed 1 year ago

wilkinsona commented 1 year ago

Switching Initializr to this backend has revealed an encoding problem that causes conversion to fail:

Caused by: org.jruby.exceptions.EncodingError$CompatibilityError: (CompatibilityError) incompatible character encodings: UTF-8 and US-ASCII
    at org.jruby.RubyString.+ (org/jruby/RubyString.java:1180)
    at RUBY.postprocess (uri:classloader:/gems/spring-asciidoctor-backends-0.0.0/lib/spring-asciidoctor-backends/spring-html5-converter.rb:80)
    at RUBY.convert (uri:classloader:/gems/spring-asciidoctor-backends-0.0.0/lib/spring-asciidoctor-backends/spring-html5-converter.rb:44)
    at RUBY.convert (uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/document.rb:944)
    at RUBY.convert (uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/convert.rb:117)
    at RUBY.convert_file (uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/convert.rb:189)
    at org.jruby.RubyIO.open (org/jruby/RubyIO.java:1158)
    at RUBY.convert_file (uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/convert.rb:189)

The code in question is:

https://github.com/spring-io/spring-asciidoctor-backends/blob/e7ef27e1bbf24f69c4b1501d7322b8abff1a286a/src/main/ruby/lib/spring-asciidoctor-backends/spring-html5-converter.rb#L71-L81

Line 79 is reading a template file and it's resulting in a US-ASCII encoded string which, on line 80, Ruby fails to concatenate with a UTF-8 string.

Asciidoctor assumes UTF-8 input and produces UTF-8 output. I think the backend should make the same input assumption and always load the template file as UTF-8.