relaton / relaton-render

Gem to render ISO 690 XML serialisation into HTML
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Crash in render/fields/fields.rb with metanorma-ieee document #46

Closed ronaldtse closed 1 year ago

ronaldtse commented 1 year ago

From https://github.com/metanorma/SWF-Corpus_and_IEEEP2874-D2/issues/24

Trace:

Metanorma XML Syntax: (XML Line 006288:254): character content of element "stage" invalid; must be equal to "approved", "draft", "superseded" or "withdrawn"
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-render-0.5.12/lib/relaton/render/fields/fields.rb:112:in `role_inflect'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-render-0.5.12/lib/relaton/render/fields/fields.rb:36:in `role_fields_format'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-render-0.5.12/lib/relaton/render/fields/fields.rb:12:in `compound_fields_format'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-render-0.5.12/lib/relaton/render/general/render.rb:170:in `block in citations1'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-render-0.5.12/lib/relaton/render/general/render.rb:168:in `each'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-render-0.5.12/lib/relaton/render/general/render.rb:168:in `each_with_object'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-render-0.5.12/lib/relaton/render/general/render.rb:168:in `with_index'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-render-0.5.12/lib/relaton/render/general/render.rb:168:in `citations1'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-render-0.5.12/lib/relaton/render/general/render.rb:150:in `render_all'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/isodoc-2.5.10/lib/isodoc/presentation_function/refs.rb:28:in `references_render'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/metanorma-ieee-1.0.15/lib/isodoc/ieee/presentation_ref.rb:48:in `references_render'
ronaldtse commented 1 year ago

The content of the document has not changed since Jan, so it's an implementation bug?

opoudjis commented 1 year ago

Potentially a missing plural of a new role like "Authoriser", but if so, that role should not be being surfaced to begin with. Also need to default to using descriptions instead of roles, when defined (outside of "editor", which is well-understood).

ronaldtse commented 1 year ago

All IETF RFCs now contain <role type="authorizer" />. There are 2 instances of them in the document. We need to fix this ASAP. Thanks.

e.g.

<bibitem id="http2_rfc" type="standard" schema-version="v1.2.1">
    <fetched>2023-01-17</fetched>
    <title type="main" format="text/plain">Hypertext Transfer Protocol Version 2 (HTTP/2)</title>
    <uri type="src">https://www.rfc-editor.org/info/rfc7540</uri>
    <docidentifier type="IETF" primary="true">RFC 7540</docidentifier>
    <docidentifier type="DOI">10.17487/RFC7540</docidentifier>
    <docnumber>RFC7540</docnumber>
    <date type="published">
        <on>2015-05</on>
    </date>
    <contributor>
        <role type="author" />
        <person>
            <name>
                <completename language="en" script="Latn">M. Belshe</completename>
            </name>
        </person>
    </contributor>
    <contributor>
        <role type="author" />
        <person>
            <name>
                <completename language="en" script="Latn">R. Peon</completename>
            </name>
        </person>
    </contributor>
    <contributor>
        <role type="editor" />
        <person>
            <name>
                <completename language="en" script="Latn">M. Thomson</completename>
            </name>
        </person>
    </contributor>
    <contributor>
        <role type="publisher" />
        <organization>
            <name>RFC Publisher</name>
        </organization>
    </contributor>
    <contributor>
        <role type="authorizer" />
        <organization>
            <name>RFC Series</name>
        </organization>
    </contributor>
    <language>en</language>
    <script>Latn</script>
    <abstract format="text/html" language="en" script="Latn">
        <p id="_85e8a858-d5fd-aed6-31c8-95b594313ebf">This specification describes an optimized
            expression of the semantics of the Hypertext Transfer Protocol (HTTP), referred to as
            HTTP version 2 (HTTP/2). HTTP/2 enables a more efficient use of network resources and a
            reduced perception of latency by introducing header field compression and allowing
            multiple concurrent exchanges on the same connection. It also introduces unsolicited
            push of representations from servers to clients.</p>
        <p id="_2724fea8-5493-878f-fa17-1b11779c0603">This specification is an alternative to, but
            does not obsolete, the HTTP/1.1 message syntax. HTTP’s existing semantics remain
            unchanged.</p>
    </abstract>
    <relation type="obsoletedBy">
        <bibitem>
            <formattedref format="text/plain">RFC9113</formattedref>
            <docidentifier type="IETF" primary="true">RFC9113</docidentifier>
        </bibitem>
    </relation>
    <series>
        <title format="text/plain">RFC</title>
        <number>7540</number>
    </series>
    <keyword>HTTP</keyword>
    <keyword>SPDY</keyword>
    <keyword>Web</keyword>
</bibitem>
opoudjis commented 1 year ago

Cannot currently replicate: IEEE P2874 generates correctly.

Screenshot 2023-08-10 at 12 24 52
opoudjis commented 1 year ago

I have not updated the relevant code recently, so I don't understand why I can't replicate the crash. @ronaldtse please confirm with me steps you took to replicate, but I'm just compiling in metanorma p2876.adoc with latest libraries.

opoudjis commented 1 year ago

Whatever the issue is, it is NOT authorizer:

      def role_inflect(contribs, role)
        role.nil? || contribs.size.zero? || 
          %w(author publisher distributor
             authorizer).include?(role) and return nil
        number = contribs.size > 1 ? "pl" : "sg"
        @r.i18n.get[role][number] || role
      end

I suspect my Relaton cache and Reese's are not in sync: clearing relaton...

opoudjis commented 1 year ago

I've replicated the issue now. I have a more secure version of the code about, but curious to see what role is triggering it...

opoudjis commented 1 year ago

It's "Chair".

I was about to get all angry and complain about Chair being put into the role, but I'm delighted to find that

(a) Chair is appearing in Description, not Role, as I had requested, for OASIS MQTT Version 5.0 (b) I am already doing what I had said I would do, prioritise descriptions over roles where available.

Fixing in relaton-render.

opoudjis commented 1 year ago

So if it doesn't find a plural in the i18n file for the role or description, it will use the singular it is given.