metanorma-ietf 3.7.16 → 3.7.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6017975715700fdc60b2600471d983155750c2a7686cda5bca82fa68ce7383fc
4
- data.tar.gz: d5db755aeba979c55aa1b1535c87f3500e140ca04ce2dd1b8563b7e5f606311f
3
+ metadata.gz: 8e7a844318fabb97ac4116d637f592ea9511d61130fb19dcaa6b1a16f01b4864
4
+ data.tar.gz: 8303922ecb675bd9d652cccad40b5ca10a9f90be517f76a672b60f87ba617bd9
5
5
  SHA512:
6
- metadata.gz: 92c566797f915c4b70921a87222ac1e081f11a5662483d93fb80ef186455f5adc82c563bb5812f97d6e9a81d220345729e8c94e831a2b1bee2285594d2c92ace
7
- data.tar.gz: 77c73d1853cd751c2544dfd9ea96644a76b01c3dd873c026cf0fe5e74fb6cc5ac9594857359913a43f90153d98404aa2f3903db8f8ac8412a85696f63540f73e
6
+ metadata.gz: b297a8195b7598a7ff83369a2e13d864110a4793b8e9d7cafc415fac967b107e2e2f9c14f8f6c24c29a61e055faf27fa0afecc116e836479559832c3e035f5db
7
+ data.tar.gz: 6760c0279f09ba2f927a128504c73db60eb075134b2d5cdef7dbbfc37300a6db88e1a7b3f3ae67f8552d1ba6fa2665a8183ff5d40a78ded4bf585881f0e1540a
@@ -15,6 +15,92 @@ module Metanorma
15
15
  "IETF_4": { category: "Document Attributes",
16
16
  error: "IETF: unrecognised working group %s",
17
17
  severity: 1 },
18
+ # RFC XML emission validation (idnits3 submission-check
19
+ # findings on the Rfcxml model); severity 0 aborts the
20
+ # compile, 2 is an author-content warning
21
+ "IETF_5": { category: "RFC XML stream",
22
+ error: "Unknown submissionType (stream) on <rfc> " \
23
+ "element (:submission-type: %s): must be one of %s",
24
+ severity: 0 },
25
+ "IETF_6": { category: "RFC XML stream",
26
+ error: "The category of <rfc> (:intended-series: " \
27
+ "TYPE NUMBER) is invalid for the %s stream: must " \
28
+ "be one of %s, but is %s",
29
+ severity: 0 },
30
+ "IETF_7": { category: "RFC XML stream",
31
+ error: "The stream setting of <front> <seriesInfo> " \
32
+ "(%s) is inconsistent with the submissionType of " \
33
+ "<rfc> (%s)",
34
+ severity: 0 },
35
+ "IETF_8": { category: "RFC XML stream",
36
+ error: "Expected no consensus setting for the %s " \
37
+ "stream (:consensus: %s); remove the :consensus: " \
38
+ "document attribute",
39
+ severity: 0 },
40
+ "IETF_9": { category: "RFC XML stream",
41
+ error: "Expected no consensus setting for the IRTF " \
42
+ "stream with no workgroup (:consensus: %s); " \
43
+ "declare :workgroup: or remove :consensus:",
44
+ severity: 0 },
45
+ "IETF_10": { category: "RFC XML stream",
46
+ error: "The ipr attribute '%s' withholds the right " \
47
+ "to produce derivative works (RFC 5378, section " \
48
+ "3.3), so it can't be used in the IETF stream; " \
49
+ "use ipr='trust200902' (or 'pre5378Trust200902')",
50
+ severity: 0 },
51
+ "IETF_11": { category: "RFC XML stream",
52
+ error: "The document name %s implies the %s " \
53
+ "stream, but the rfc tag declares " \
54
+ "submissionType='%s' (:submission-type:); align " \
55
+ "the two",
56
+ severity: 0 },
57
+ "IETF_12": { category: "RFC XML submission",
58
+ error: "The abstract section is missing (an " \
59
+ ":abstract: block or [abstract] section): the " \
60
+ "IETF submission check requires it",
61
+ severity: 0 },
62
+ "IETF_13": { category: "RFC XML submission",
63
+ error: "The abstract section is present but " \
64
+ "contains no content (idnits3: at least 1 <t>, " \
65
+ "<ol>, <ul> or <dl> element)",
66
+ severity: 2 },
67
+ "IETF_14": { category: "RFC XML text output",
68
+ error: "The <%s> has lines wider than the 72 " \
69
+ "columns of xml2rfc's text output (widest is " \
70
+ "%s); xml2rfc will wrap or truncate them",
71
+ severity: 2 },
72
+ "IETF_15": { category: "RFC XML references",
73
+ error: "The reference %s is listed in the " \
74
+ "References section but is not mentioned in the " \
75
+ "document text",
76
+ severity: 2 },
77
+ "IETF_16": { category: "RFC XML vocabulary",
78
+ error: "The %s attribute of <%s> is deprecated " \
79
+ "(%s=\"%s\"): it must not be emitted",
80
+ severity: 1 },
81
+ "IETF_17": { category: "RFC XML vocabulary",
82
+ error: "The <%s> element is deprecated and must " \
83
+ "not be emitted",
84
+ severity: 1 },
85
+ "IETF_18": { category: "RFC XML front matter",
86
+ error: "The <author> is missing its fullname " \
87
+ "attribute",
88
+ severity: 2 },
89
+ "IETF_19": { category: "RFC XML front matter",
90
+ error: "There are more than 5 authors / editors; " \
91
+ "discuss the need with the relevant stream " \
92
+ "leadership",
93
+ severity: 3 },
94
+ "IETF_20": { category: "RFC XML text output",
95
+ error: "The <%s> contains tab characters, which " \
96
+ "xml2rfc's text output does not align; use " \
97
+ "spaces",
98
+ severity: 2 },
99
+ "IETF_21": { category: "RFC XML submission",
100
+ error: "The IETF submission check expects the " \
101
+ "submitted file to be named %s.xml; rename the " \
102
+ "output file before submitting it",
103
+ severity: 3 },
18
104
  }.freeze
19
105
  # rubocop:enable Naming/VariableNumber
20
106
 
@@ -75,19 +75,27 @@ module Metanorma
75
75
 
76
76
  # Mirror convert_forward's serialisation tail: bare-ampersand
77
77
  # escaping (#302: was present on the library API path only),
78
- # non-ASCII <u> wrapping (N11), then validation. Content errors
79
- # are stashed so the output stage can quarantine (#302: the
80
- # released leg moved invalid output to .err and halted; the
78
+ # non-ASCII <u> wrapping (N11), then validation. Findings are
79
+ # recorded in the flavor log catalog through Metanorma::Utils::Log
80
+ # (the Metanorma::Standoc::Validate shape); abort-severity
81
+ # entries are stashed so the output stage can quarantine (#302:
82
+ # the released leg moved invalid output to .err and halted; the
81
83
  # port had reduced that to warnings)
82
84
  def rfc_post_process(xml, transformer, options)
83
85
  xml = Transformer.escape_bare_ampersands(xml)
84
86
  xml = Transformer.u_cleanup(xml)
85
87
  @rfc_content_errors = []
88
+ @rfc_validator = nil
86
89
  if options[:validate]
90
+ rfc = transformer.rfc
91
+ @rfc_validator = RfcValidate.new
92
+ @fatal_rfc_errors = @rfc_validator.content_validate(rfc, transformer.doc)
93
+ @rfc_validator.content_warnings(rfc)
94
+ @rfc_validator.record_filename_hint(rfc.doc_name)
95
+ @rfc_content_errors = @fatal_rfc_errors +
96
+ transformer.content_validate(xml)
87
97
  transformer.schema_validate(xml)
88
98
  .each { |e| warn "RFC XML: #{e}" }
89
- @rfc_content_errors = transformer.content_validate(xml)
90
- @rfc_content_errors.each { |e| warn "RFC XML: #{e}" }
91
99
  end
92
100
  xml
93
101
  end
@@ -100,9 +108,12 @@ module Metanorma
100
108
  super(isodoc_node, inname, outname, format,
101
109
  options.merge(validate: true))
102
110
  if @rfc_content_errors&.any?
111
+ @rfc_validator&.write(outname)
103
112
  FileUtils.mv(outname, "#{outname}.err", force: true)
113
+ warn "FATAL ERRORS:\n\n#{@fatal_rfc_errors.join("\n\n")}" if @fatal_rfc_errors.any?
104
114
  warn "Cannot continue processing"
105
115
  else
116
+ @rfc_validator&.entries? and @rfc_validator.write(outname)
106
117
  @done_rfc = true
107
118
  end
108
119
  when :txt, :pdf, :html
@@ -60,6 +60,7 @@
60
60
  <value>IAB</value>
61
61
  <value>IRTF</value>
62
62
  <value>independent</value>
63
+ <value>editorial</value>
63
64
  </choice>
64
65
  </attribute>
65
66
  </optional>
@@ -1265,6 +1266,8 @@
1265
1266
  <choice>
1266
1267
  <ref name="artset"/>
1267
1268
  <ref name="artwork"/>
1269
+ <ref name="aside"/>
1270
+ <ref name="blockquote"/>
1268
1271
  <ref name="dl"/>
1269
1272
  <ref name="figure"/>
1270
1273
  <ref name="ol"/>
@@ -1576,6 +1579,8 @@
1576
1579
  <ref name="iref"/>
1577
1580
  <ref name="relref"/>
1578
1581
  <ref name="strong"/>
1582
+ <ref name="sub"/>
1583
+ <ref name="sup"/>
1579
1584
  <ref name="tt"/>
1580
1585
  <ref name="xref"/>
1581
1586
  </choice>
@@ -1600,6 +1605,8 @@
1600
1605
  <ref name="iref"/>
1601
1606
  <ref name="relref"/>
1602
1607
  <ref name="strong"/>
1608
+ <ref name="sub"/>
1609
+ <ref name="sup"/>
1603
1610
  <ref name="tt"/>
1604
1611
  <ref name="xref"/>
1605
1612
  </choice>
@@ -2378,6 +2385,7 @@
2378
2385
  <value>IAB</value>
2379
2386
  <value>IRTF</value>
2380
2387
  <value>independent</value>
2388
+ <value>editorial</value>
2381
2389
  </choice>
2382
2390
  </optional>
2383
2391
  </element>
@@ -2430,6 +2438,7 @@
2430
2438
  <value>IAB</value>
2431
2439
  <value>IRTF</value>
2432
2440
  <value>independent</value>
2441
+ <value>editorial</value>
2433
2442
  </choice>
2434
2443
  </attribute>
2435
2444
  </optional>
@@ -4,6 +4,12 @@ module Metanorma
4
4
  module Ietf
5
5
  module Transformer
6
6
  module FrontTransformer
7
+ # RFC 7991 s2.29 subseries pointer names, keyed by the
8
+ # intended-series title the flavor accepts
9
+ SERIES_INFO_NAMES = {
10
+ "standard" => "STD", "std" => "STD", "full-standard" => "STD",
11
+ "bcp" => "BCP", "fyi" => "FYI",
12
+ }.freeze
7
13
 
8
14
  def build_front
9
15
  front = Rfcxml::V3::Front.new
@@ -33,6 +39,10 @@ module Metanorma
33
39
  title
34
40
  end
35
41
 
42
+ # No status/stream on the front seriesInfo: the idnits3
43
+ # submission check flags both as deprecated on the author's
44
+ # seriesInfo (the values live on <rfc category/submissionType>),
45
+ # and xml2rfc's preptool re-adds the stream itself (5.4.2.1)
36
46
  def build_series_info
37
47
  infos = []
38
48
  if rfc?
@@ -42,41 +52,12 @@ module Metanorma
42
52
  ascii_val = Sterile.transliterate(si.value)
43
53
  si.ascii_value = ascii_val unless ascii_val == si.value
44
54
  si.ascii_name = "RFC"
45
- # the released path passes the metadata stage through
46
- # (capitalised text; numeric stages stay as-is), defaulting
47
- # to Published (WS3, metadata_spec)
48
- stage = model_attr(bibdata, :status)
49
- stage_text = stage && ls_text(model_attr(stage, :stage) || stage)
50
- si.status = if stage_text && !stage_text.strip.empty?
51
- stage_text.strip.capitalize
52
- else
53
- "Published"
54
- end
55
- si.stream = extract_submission_type
56
55
  infos << si
57
56
  else
58
57
  si = Rfcxml::V3::SeriesInfo.new
59
58
  si.name = "Internet-Draft"
60
59
  si.value = extract_doc_name.to_s
61
60
  si.ascii_name = "Internet-Draft"
62
- si.stream = extract_submission_type
63
- # status = metadata stage, as on the RFC branch (the
64
- # released path uses the stage for both); intended-series
65
- # title only as fallback (WS3, metadata_spec)
66
- stage = model_attr(bibdata, :status)
67
- stage_text = stage && ls_text(model_attr(stage, :stage) || stage)
68
- if stage_text && !stage_text.strip.empty?
69
- si.status = stage_text.strip.capitalize
70
- else
71
- series_list = to_array(bibdata.series)
72
- series_list.each do |s|
73
- next unless s.type == "intended"
74
- title = ls_text(s.title)
75
- si.status = title&.capitalize || "Informational"
76
- break
77
- end
78
- end
79
- si.status ||= "Informational"
80
61
  infos << si
81
62
  end
82
63
 
@@ -85,12 +66,21 @@ module Metanorma
85
66
  series_list = [series_list] unless series_list.is_a?(Array)
86
67
  series_list.each do |s|
87
68
  next unless s.type == "intended"
88
- si = Rfcxml::V3::SeriesInfo.new
89
- si.name = ""
90
- # the intended-series number ("BCP 14" -> value=14, #298)
69
+ # RFC 7991 s2.29: the subseries pointers carry a name and
70
+ # number ("BCP 14" -> name="BCP" value="14", #298); the
71
+ # informational/experimental/historic statuses have no
72
+ # subseries (they live on the rfc category), and a
73
+ # seriesInfo without a number has nothing valid to point
74
+ # at — the former empty name="" value="" entries were
75
+ # schema-legal junk
76
+ title = ls_text(s.title)
77
+ name = title && SERIES_INFO_NAMES[title.downcase]
91
78
  num = s.respond_to?(:number) ? ls_text(s.number) : nil
92
- si.value = num && !num.to_s.strip.empty? ? num.to_s.strip : ""
93
- si.status = ls_text(s.title)
79
+ num = num&.strip
80
+ next unless name && num && !num.empty?
81
+ si = Rfcxml::V3::SeriesInfo.new
82
+ si.name = name
83
+ si.value = num
94
84
  infos << si
95
85
  end
96
86
  end
@@ -34,7 +34,7 @@ module Metanorma
34
34
  include CleanupTransformer
35
35
  include ValidationTransformer
36
36
 
37
- attr_reader :doc, :options, :xrefs
37
+ attr_reader :doc, :options, :xrefs, :rfc
38
38
 
39
39
  def initialize(doc, options = {})
40
40
  @doc = doc
@@ -55,7 +55,7 @@ module Metanorma
55
55
  rfc.middle = build_middle
56
56
  rfc.back = build_back
57
57
  cleanup(rfc)
58
- rfc
58
+ @rfc = rfc
59
59
  end
60
60
 
61
61
 
@@ -119,7 +119,16 @@ module Metanorma
119
119
  return SERIES2CATEGORY.fetch(title.downcase, "std") if title
120
120
  end
121
121
  end
122
- "std"
122
+ category_default
123
+ end
124
+
125
+ # With no intended series declared, fall back to a category the
126
+ # stream actually carries (RFC 7841): xml2rfc's preptool dies
127
+ # on stream/category combinations it has no boilerplate for,
128
+ # and the former blanket std default handed every independent
129
+ # document one
130
+ def category_default
131
+ extract_submission_type == "IETF" ? "std" : "info"
123
132
  end
124
133
 
125
134
  def extract_doc_name
@@ -0,0 +1,269 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Ietf
5
+ module Transformer
6
+ # RFC XML content checks on the Rfcxml::V3 model. The
7
+ # transformer law is model-driven: content rules walk the model
8
+ # objects, never the serialised XML (only the RelaxNG schema
9
+ # check and the released-path content transplant remain on the
10
+ # XML side). All rules here port idnits3 submission-check
11
+ # findings; they are returned as catalog-id/params pairs for
12
+ # Validate to record through the metanorma log.
13
+ module ModelValidation
14
+ RFC7841_STREAMS = %w(IETF IAB IRTF independent editorial).freeze
15
+
16
+ # RFC 7841 s2: the category each stream may carry; source of
17
+ # truth is the xml2rfc boilerplate_rfc_7841.py
18
+ # boilerplate_rfc_status_of_memo table
19
+ RFC7841_STREAM_CATEGORIES = {
20
+ "IETF" => %w(std bcp exp historic info),
21
+ "IAB" => %w(info historic),
22
+ "IRTF" => %w(exp historic info),
23
+ "independent" => %w(exp historic info),
24
+ "editorial" => %w(info),
25
+ }.freeze
26
+
27
+ module_function
28
+
29
+ def validate(rfc, doc = nil)
30
+ submission_type_findings(rfc, doc) + abstract_findings(rfc)
31
+ end
32
+
33
+ def submission_type_findings(rfc, doc = nil)
34
+ ret = []
35
+ ret += submission_type_enum_findings(rfc)
36
+ ret += stream_category_findings(rfc)
37
+ ret += series_info_stream_findings(rfc)
38
+ ret += consensus_findings(rfc, doc)
39
+ ret += ipr_stream_findings(rfc)
40
+ ret += docname_stream_findings(rfc)
41
+ ret
42
+ end
43
+
44
+ # idnits3 SUBMISSION_TYPE_INVALID
45
+ def submission_type_enum_findings(rfc)
46
+ st = rfc.submission_type or return []
47
+ RFC7841_STREAMS.include?(st) or
48
+ return [["IETF_5", [st, RFC7841_STREAMS.join(", ")]]]
49
+ []
50
+ end
51
+
52
+ def stream_category_findings(rfc)
53
+ st = rfc.submission_type || "IETF"
54
+ cat = rfc.category or return []
55
+ legal = RFC7841_STREAM_CATEGORIES[st] or return []
56
+ legal.include?(cat) or
57
+ return [["IETF_6",
58
+ [st, legal.join(", "), cat]]]
59
+ []
60
+ end
61
+
62
+ # xml2rfc preptool 5.4.2.1: the front seriesInfo stream and
63
+ # the rfc submissionType agree
64
+ def series_info_stream_findings(rfc)
65
+ st = rfc.submission_type || "IETF"
66
+ rfc.front&.series_info.to_a.each do |si|
67
+ si.stream && si.stream != st and
68
+ return [["IETF_7", [si.stream, st]]]
69
+ end
70
+ []
71
+ end
72
+
73
+ # xml2rfc preptool 5.4.2.2: the independent and editorial
74
+ # streams take no consensus setting, and the IRTF stream only
75
+ # when the document names a workgroup. The authored consensus
76
+ # comes from the input model's bibdata ext: the Rfcxml model
77
+ # default ("false") is indistinguishable from an authored
78
+ # false through the plain accessor
79
+ def consensus_findings(rfc, doc = nil)
80
+ st = rfc.submission_type || "IETF"
81
+ c = doc ? authored_consensus(doc) : authored_fallback(rfc)
82
+ return [] unless c
83
+ if %w(independent editorial).include?(st)
84
+ return [["IETF_8", [st, c]]]
85
+ end
86
+ if st == "IRTF" && rfc.front&.workgroup.to_a.empty?
87
+ return [["IETF_9", [c]]]
88
+ end
89
+ []
90
+ end
91
+
92
+ # the same source the emission reads: bibdata ext consensus
93
+ def authored_consensus(doc)
94
+ ext = doc&.bibdata&.ext and return ext.consensus
95
+ nil
96
+ end
97
+
98
+ # without the input model the Rfcxml accessor cannot
99
+ # distinguish an authored false from the model default: only a
100
+ # non-default value counts as authored
101
+ def authored_fallback(rfc)
102
+ c = rfc.consensus
103
+ c == "false" ? nil : c
104
+ end
105
+
106
+ # idnits3 FORBIDDEN_IPR_VALUE_FOR_STREAM (RFC 5378 s3.3)
107
+ RESTRICTED_IPR_VALUES = %w(noModificationTrust200902
108
+ noDerivativesTrust200902).freeze
109
+
110
+ def ipr_stream_findings(rfc)
111
+ return [] if rfc.ipr == "none"
112
+ return [] unless RESTRICTED_IPR_VALUES.include?(rfc.ipr)
113
+ return [] unless stream_of(rfc) == "ietf"
114
+
115
+ [["IETF_10", [rfc.ipr]]]
116
+ end
117
+
118
+ # idnits3 SUBMISSION_TYPE_MISMATCH: draft-iab-... and
119
+ # draft-irtf-... names imply their stream
120
+ def docname_stream_findings(rfc)
121
+ name = rfc.doc_name or return []
122
+ prefix = name.downcase.match(/\Adraft-([a-z0-9]+)-/)&.captures&.first
123
+ return [] unless %w(iab irtf).include?(prefix)
124
+ return [] if stream_of(rfc) == prefix
125
+
126
+ [["IETF_11",
127
+ [name, "#{prefix.upcase}", rfc.submission_type.to_s]]]
128
+ end
129
+
130
+ def stream_of(rfc)
131
+ rfc.submission_type&.downcase || "ietf"
132
+ end
133
+
134
+ # idnits3 MISSING_ABSTRACT_SECTION: the abstract is required
135
+ # at submission (https://authors.ietf.org/required-content)
136
+ def abstract_findings(rfc)
137
+ a = rfc.front&.abstract or return [["IETF_12", []]]
138
+ a.t.to_a.empty? && a.ol.to_a.empty? && a.ul.to_a.empty? &&
139
+ a.dl.to_a.empty? or return []
140
+ [["IETF_13", []]]
141
+ end
142
+
143
+ # idnits3 ARTWORK_TOO_WIDE: xml2rfc's text output is 72
144
+ # columns; <sourcecode> is indented by 3 of them
145
+ TEXT_LINE_WIDTH = 72
146
+ SOURCECODE_INDENT = 3
147
+
148
+ def artwork_width_findings(rfc)
149
+ walk(rfc).each_with_object([]) do |node, ret|
150
+ case node
151
+ when Rfcxml::V3::Artwork
152
+ width_findings(node, node.content.to_s, TEXT_LINE_WIDTH, ret)
153
+ when Rfcxml::V3::Sourcecode
154
+ width_findings(node, node.content.to_a.join("\n"),
155
+ TEXT_LINE_WIDTH - SOURCECODE_INDENT, ret)
156
+ end
157
+ end
158
+ end
159
+
160
+ def width_findings(node, content, budget, ret)
161
+ widest = content.to_s.lines.map(&:chomp).map(&:length).max || 0
162
+ widest > budget and
163
+ ret << ["IETF_14", [element_name_of(node), widest.to_s]]
164
+ end
165
+
166
+ # idnits3 REFERENCE_NOT_USED. Divergence from idnits3: it
167
+ # counts <xref> targets only, while our flavor renders
168
+ # eref-style citations as <relref>, so both count as uses
169
+ def references_used_findings(rfc)
170
+ anchors = walk(rfc).select { |n| n.is_a?(Rfcxml::V3::Reference) }
171
+ .map(&:anchor).compact.uniq
172
+ return [] if anchors.empty?
173
+ used = walk(rfc)
174
+ .select { |n| n.is_a?(Rfcxml::V3::Xref) || n.is_a?(Rfcxml::V3::Relref) }
175
+ .map(&:target).compact
176
+ anchors.uniq.reject { |a| used.include?(a) }
177
+ .map { |a| ["IETF_15", [a]] }
178
+ end
179
+
180
+ # The idnits3 deprecated-attribute/element tables (xml2rfc
181
+ # base.py deprecated_attributes / RFC 7991), keyed by the XML
182
+ # names the mappings emit: emission must never set them
183
+ DEPRECATED_ATTRIBUTES = {
184
+ "artwork" => %w(height width xml:space),
185
+ "figure" => %w(align alt height src suppress-title title width),
186
+ "note" => %w(title),
187
+ "references" => %w(title),
188
+ "section" => %w(title),
189
+ "seriesInfo" => %w(status stream),
190
+ "t" => %w(hangText),
191
+ "texttable" => %w(title),
192
+ "xref" => %w(pageno),
193
+ }.freeze
194
+ DEPRECATED_ELEMENTS = %w(spanx texttable ttcol vspace).freeze
195
+
196
+ def deprecated_findings(rfc)
197
+ ret = []
198
+ walk(rfc).each do |node|
199
+ tag = element_name_of(node)
200
+ DEPRECATED_ELEMENTS.include?(tag) and
201
+ ret << ["IETF_17", [tag]]
202
+ dep = DEPRECATED_ATTRIBUTES[tag] or next
203
+ node.class.mappings[:xml].attributes.each do |xml_name, rule|
204
+ next unless dep.include?(xml_name)
205
+ val = node.public_send(rule.to)
206
+ next if val.nil? || val.to_s.empty?
207
+ ret << ["IETF_16",
208
+ [xml_name, tag, xml_name, val.to_s]]
209
+ end
210
+ end
211
+ ret
212
+ end
213
+
214
+ # idnits3 MISSING_AUTHOR_FULLNAME / TOO_MANY_AUTHORS
215
+ def author_findings(rfc)
216
+ ret = []
217
+ authors = rfc.front&.author.to_a
218
+ authors.each do |a|
219
+ a.fullname.to_s.strip.empty? and
220
+ ret << ["IETF_18", []]
221
+ end
222
+ authors.size > 5 and
223
+ ret << ["IETF_19", []]
224
+ ret
225
+ end
226
+
227
+ # idnits3 TABS_IN_CODE: tabs break xml2rfc's text alignment
228
+ def tabs_findings(rfc)
229
+ walk(rfc).each_with_object([]) do |node, ret|
230
+ next unless node.is_a?(Rfcxml::V3::Artwork) ||
231
+ node.is_a?(Rfcxml::V3::Sourcecode)
232
+ content = node.is_a?(Rfcxml::V3::Sourcecode) ? node.content.to_a.join("\n") : node.content.to_s
233
+ content.include?("\t") and
234
+ ret << ["IETF_20", [element_name_of(node)]]
235
+ end
236
+ end
237
+
238
+ # Author-content findings that do not abort the compile
239
+ def warnings(rfc)
240
+ artwork_width_findings(rfc) + references_used_findings(rfc) +
241
+ deprecated_findings(rfc) + author_findings(rfc) +
242
+ tabs_findings(rfc)
243
+ end
244
+
245
+ # Depth-first walk over every model node, including models
246
+ # nested in collections
247
+ def walk(node, seen = {}.compare_by_identity, &block)
248
+ return to_enum(__method__, node) unless block
249
+ return unless node.is_a?(Lutaml::Model::Serializable)
250
+ return if seen.key?(node)
251
+ seen[node] = true
252
+ block.call(node)
253
+ node.class.attributes.each_value do |attr|
254
+ value = node.public_send(attr.name)
255
+ case value
256
+ when Array then value.each { |v| walk(v, seen, &block) }
257
+ when Lutaml::Model::Serializable then walk(value, seen, &block)
258
+ end
259
+ end
260
+ end
261
+
262
+ # The XML element name the mappings emit for this node
263
+ def element_name_of(node)
264
+ node.class.mappings[:xml].element_name
265
+ end
266
+ end
267
+ end
268
+ end
269
+ end
@@ -242,6 +242,7 @@ module Metanorma
242
242
  "#{xml.root['ipr']}"]
243
243
  []
244
244
  end
245
+
245
246
  end
246
247
  end
247
248
  end
@@ -14,6 +14,7 @@ module Metanorma
14
14
  autoload :NullObjects, "metanorma/ietf/transformer/null_objects"
15
15
  autoload :OrderTracker, "metanorma/ietf/transformer/order_tracker"
16
16
  autoload :IetfToRfcV3, "metanorma/ietf/transformer/ietf_to_rfc_v3"
17
+ autoload :ModelValidation, "metanorma/ietf/transformer/model_validation"
17
18
  autoload :RfcV3ToIetf, "metanorma/ietf/transformer/rfc_v3_to_ietf"
18
19
 
19
20
  class Error < StandardError; end
@@ -62,8 +63,13 @@ module Metanorma
62
63
  xml = u_cleanup(xml)
63
64
 
64
65
  if options[:validate]
65
- errors = transformer.validate_rfc_xml(xml)
66
- errors.each { |e| warn "RFC XML: #{e}" }
66
+ validator = RfcValidate.new
67
+ fatal = validator.content_validate(rfc, doc)
68
+ validator.content_warnings(rfc)
69
+ fatal.empty? or
70
+ raise Error, "FATAL ERRORS:\n\n#{fatal.join("\n\n")}"
71
+ transformer.validate_rfc_xml(xml)
72
+ .each { |e| warn "RFC XML: #{e}" }
67
73
  end
68
74
 
69
75
  xml
@@ -47,5 +47,60 @@ module Metanorma
47
47
  "ietf.rng"
48
48
  end
49
49
  end
50
+
51
+ # RFC XML emission validation for the processor's document-model
52
+ # leg, in the Metanorma::Standoc::Validate shape: findings are
53
+ # recorded through Metanorma::Utils::Log against the flavor
54
+ # catalog (severity 0 aborts the compile), the full report is
55
+ # rendered to the standard .err.html artifact, and the submitted
56
+ # filename hint is logged as info.
57
+ class RfcValidate
58
+ def initialize
59
+ @log = Metanorma::Utils::Log.new(Converter::IETF_LOG_MESSAGES)
60
+ end
61
+
62
+ # Returns the abort entries (clean_abort wording). doc is the
63
+ # input metanorma-document model, for findings that need the
64
+ # authored value (the Rfcxml model default is indistinguishable
65
+ # from an authored one through the plain accessor)
66
+ def content_validate(rfc, doc = nil)
67
+ Transformer::ModelValidation.validate(rfc, doc)
68
+ .each do |id, params|
69
+ @log.add(id, nil, params: params)
70
+ end
71
+ @log.abort_messages
72
+ end
73
+
74
+ def content_warnings(rfc)
75
+ Transformer::ModelValidation.warnings(rfc).each do |id, params|
76
+ @log.add(id, nil, params: params)
77
+ end
78
+ end
79
+
80
+ # idnits3 FILENAME_DOCNAME_MISMATCH / FILENAME_TOO_MANY_DOTS
81
+ # apply to the submitted file, which Datatracker requires to be
82
+ # named after the draft; our build artifact keeps the source
83
+ # base name
84
+ def record_filename_hint(doc_name)
85
+ doc_name or return
86
+ @log.add("IETF_21", nil, params: [doc_name])
87
+ end
88
+
89
+ def fatal?
90
+ !@log.abort_messages.empty?
91
+ end
92
+
93
+ def entries?
94
+ !@log.messages.empty?
95
+ end
96
+
97
+ def write(filename)
98
+ @log.save_to(filename)
99
+ @log.write
100
+ # the same name save_to computes for the report
101
+ File.join(File.dirname(filename),
102
+ "#{File.basename(filename, '.*')}.err.html")
103
+ end
104
+ end
50
105
  end
51
106
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Ietf
3
- VERSION = "3.7.16".freeze
3
+ VERSION = "3.7.18".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-ietf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.16
4
+ version: 3.7.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -266,6 +266,7 @@ files:
266
266
  - lib/metanorma/ietf/transformer/inline_transformer.rb
267
267
  - lib/metanorma/ietf/transformer/list_transformer.rb
268
268
  - lib/metanorma/ietf/transformer/metadata_transformer.rb
269
+ - lib/metanorma/ietf/transformer/model_validation.rb
269
270
  - lib/metanorma/ietf/transformer/null_objects.rb
270
271
  - lib/metanorma/ietf/transformer/order_tracker.rb
271
272
  - lib/metanorma/ietf/transformer/reference_transformer.rb