Skip to content

If hugo have some chinese attributes for asciidoctor, asciidoctor throw error #4351

Closed
@zkaip

Description

@zkaip

if hugo have markup attribute like the follow
Screen Shot 2022-09-08 at 17 38 28

The error is happened as follow
Screen Shot 2022-09-08 at 17 19 50

then I edit lib/asciidoctor/cli/options.rb
from
attr = attr.encode UTF_8 unless attr.encoding == UTF_8
Screen Shot 2022-09-08 at 17 22 12

to
attr = attr.force_encoding UTF_8 unless attr.encoding == UTF_8
Screen Shot 2022-09-08 at 17 01 54

the bug is fixed!

Please reference my fixed to upgrade asciidoctor!

Activity

mojavelinux

mojavelinux commented on Sep 8, 2022

@mojavelinux
Member

An AsciiDoc processor assumes that all input is either UTF-8 encoded or properly labeled. See https://docs.asciidoctor.org/asciidoc/latest/normalization/. It's likely that when Hugo runs the asciidoctor command using the system call, it ends up causing mislabeled data to be passed to Asciidoctor. The proposed change would be reverting the change made for #2764. You can find information about how to relabel the strings in the following comment: #2764 (comment)

Here's what I would be willing to do. We could try .encode and if that fails, fall back to force_encoding. In other words:

            unless attr.encoding == UTF_8
              begin
                attr = attr.encode UTF_8 
              rescue ::Encoding::EncodingError
                attr = attr.force_encoding UTF_8
              end
            end

Can you try that logic and see if it works for you?

added this to the discussion milestone on Sep 8, 2022
zkaip

zkaip commented on Sep 9, 2022

@zkaip
Author

I solved this problem by modifying the source code, but I hope that this issue can also be updated in the main asciidoctor version, because, if the user passes a non-utf_8 string, then compatibility should also be done

mojavelinux

mojavelinux commented on Sep 9, 2022

@mojavelinux
Member
zkaip

zkaip commented on Sep 9, 2022

@zkaip
Author

@mojavelinux you code not worked...

if I changed the code as the follow
Screen Shot 2022-09-09 at 12 02 57

then the result is follow
Screen Shot 2022-09-09 at 12 03 55

mojavelinux

mojavelinux commented on Sep 9, 2022

@mojavelinux
Member

Thank you for testing. Let me update the code and I'll get back to you once I have something new to test.

The reason I cannot accept the code as you wrote it is that it would break compatibility with strings that are properly labeled. But I think we can find a way to support both cases.

mojavelinux

mojavelinux commented on Sep 9, 2022

@mojavelinux
Member

Can you try this code instead? It looks like I had the name of the error class wrong

 unless attr.encoding == UTF_8
  begin
    attr = attr.encode UTF_8 
  rescue ::EncodingError
    attr = attr.force_encoding UTF_8
  end
end
zkaip

zkaip commented on Sep 9, 2022

@zkaip
Author

@mojavelinux Yes, this code resolved the problem.

unless attr.encoding == UTF_8
  begin
    attr = attr.encode UTF_8 
  rescue ::EncodingError
    attr = attr.force_encoding UTF_8
  end
end
mojavelinux

mojavelinux commented on Sep 9, 2022

@mojavelinux
Member

Thanks for verifying! I'll go ahead and proceed with that change.

added a commit that references this issue on Sep 9, 2022

resolves asciidoctor#4351 force encoding of attribute data passed via…

c698b57
self-assigned this
on Sep 9, 2022
added
improvementIssues that refine or optimize existing capabilities
on Sep 9, 2022
mojavelinux

mojavelinux commented on Sep 9, 2022

@mojavelinux
Member

I'll backport this change to 2.0.x as well.

added a commit that references this issue on Sep 11, 2022

backport fix for #4351 force encoding of attribute data passed via CL…

added
v2.1.0Issues resolved in the 2.1.0 release.
v2.0.18Issues resolved in the 2.0.18 release
on Sep 11, 2022
removed
v2.1.0Issues resolved in the 2.1.0 release.
on Oct 16, 2022
modified the milestones: v2.1.x, v2.0.x on Oct 16, 2022
added a commit that references this issue on Feb 4, 2024

resolves asciidoctor#4351 force encoding of attribute data passed via…

07915e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

improvementIssues that refine or optimize existing capabilitiesv2.0.18Issues resolved in the 2.0.18 release

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @mojavelinux@zkaip

      Issue actions

        If hugo have some chinese attributes for asciidoctor, asciidoctor throw error · Issue #4351 · asciidoctor/asciidoctor