Skip to content

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

@wilkinsona

Description

@wilkinsona

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:

def postprocess(node, html)
if node.attr? 'iconfont-fontawesome'
html = html.gsub(/<link\ rel="stylesheet"(?!.*(site|font-awesome)\.css).*>\R?/, "")
else
html = html.gsub(/<link\ rel="stylesheet"(?!.*site\.css).*>\R?/, "")
end
match = html.match(/^(.*<body.*?>)(.*)(<\/body>.*)$/m)
templateFile = File.join(File.dirname(File.expand_path(__FILE__)), "body_template.html")
body = File.read(templateFile) % { :body => match[2] }
return match[1] + body + match[3]
end

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions