From 8d432b7810349caf91dec1f5b0a1ab8c879490d7 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Fri, 23 Aug 2024 01:53:34 +1000 Subject: [PATCH] security updates --- lib/metanorma/standoc/base.rb | 16 ++++++++-------- lib/metanorma/standoc/cleanup_inline.rb | 2 +- lib/metanorma/standoc/cleanup_text.rb | 4 ++-- .../standoc/datamodel/plantuml_renderer.rb | 2 +- lib/metanorma/standoc/localbib.rb | 2 +- lib/metanorma/standoc/macros.rb | 2 +- lib/metanorma/standoc/macros_plantuml.rb | 2 +- lib/metanorma/standoc/ref.rb | 2 +- lib/metanorma/standoc/ref_utility.rb | 13 +++++++------ lib/metanorma/standoc/section.rb | 4 ++-- spec/metanorma/base_spec.rb | 2 +- 11 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/metanorma/standoc/base.rb b/lib/metanorma/standoc/base.rb index 31477dd2..3eb23da3 100644 --- a/lib/metanorma/standoc/base.rb +++ b/lib/metanorma/standoc/base.rb @@ -47,15 +47,15 @@ def document1(node) def insert_xml_cr(doc) doc.gsub(%r{()}x, "\\1\n") + sourcecode|formula|quote|references|annex|appendix|title|name|note| + thead|tbody|tfoot|th|td|form|requirement|recommendation|permission| + imagemap|svgmap|preferred|admitted|related|domain|deprecates| + letter-symbol|graphical-symbol|expression|subject|abbreviation-type| + pronunciation|grammar|term|terms|termnote|termexample|termsource| + origin|termref|modification)>)}x, "\\1\n") .gsub(%r{(<(title|name))}, "\n\\1") - .gsub(%r{(]*>)\s+(]*>[^<]+)\s+}, "\\1\\2") + .gsub(%r{(]*>)\s+(]*>[^<]+)\s+}, + "\\1\\2") end def version diff --git a/lib/metanorma/standoc/cleanup_inline.rb b/lib/metanorma/standoc/cleanup_inline.rb index 56c3fe15..fafe3736 100644 --- a/lib/metanorma/standoc/cleanup_inline.rb +++ b/lib/metanorma/standoc/cleanup_inline.rb @@ -99,7 +99,7 @@ def related_cleanup(xmldoc) def key_extract_locality(elem) elem["key"].include?(",") or return elem.add_child("#{elem['key'].sub(/^[^,]+,/, '')}") - elem["key"] = elem["key"].sub(/,.*$/, "") + elem["key"] = elem["key"].sub(/(^[^,]+),.*$/, "\\1") end def concept_termbase_cleanup(elem) diff --git a/lib/metanorma/standoc/cleanup_text.rb b/lib/metanorma/standoc/cleanup_text.rb index a6b5f9ee..a18b943b 100644 --- a/lib/metanorma/standoc/cleanup_text.rb +++ b/lib/metanorma/standoc/cleanup_text.rb @@ -2,8 +2,8 @@ module Metanorma module Standoc module Cleanup def textcleanup(result) - text = result.flatten.map { |l| l.sub(/\s*\Z/, "") } * "\n" - text = text.gsub(/\s+([^<]*) }mx) { @c.decode($1) } diff --git a/lib/metanorma/standoc/datamodel/plantuml_renderer.rb b/lib/metanorma/standoc/datamodel/plantuml_renderer.rb index 7ef292ff..d1a7ff03 100644 --- a/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +++ b/lib/metanorma/standoc/datamodel/plantuml_renderer.rb @@ -15,7 +15,7 @@ def initialize(yml, plantuml_path) end def join_as_plantuml(*ary) - ary.compact.join("\n").sub(/\s+\Z/, "") + ary.compact.join("\n").sub(/(?[ \t]*)(?.*)$/ =~ line + /^(?[ \t]*)(?![ \t])(?.*)$/ =~ line prefix = prefix.gsub("\t", "\u00a0\u00a0\u00a0\u00a0") .tr(" ", "\u00a0") prefix + suffix diff --git a/lib/metanorma/standoc/macros_plantuml.rb b/lib/metanorma/standoc/macros_plantuml.rb index 1e01038e..bff667a7 100644 --- a/lib/metanorma/standoc/macros_plantuml.rb +++ b/lib/metanorma/standoc/macros_plantuml.rb @@ -71,7 +71,7 @@ def self.save_plantuml(_parent, reader, _localdir) def self.prep_source(reader) src = reader.source - reader.lines.first.sub(/\s+$/, "").match /^@startuml($| )/ or + reader.lines.first.sub(/(?[^,]+),\s*)?(?.+)\)$/.match(ret[:id]) + m = /^local-file\((?:(?[^,)]+),\s*)?(?[^)]+)\)$/ + .match(ret[:id]) m or return ret ret.merge(id: m[:id], localfile: m[:source] || "default") end @@ -88,7 +89,7 @@ def analyse_ref_dropid(ret) end def analyse_ref_repo_path(ret) - m = /^(?repo|path|attachment):\((?[^,]+),?(?[^)]*)\)$/ + m = /^(?repo|path|attachment):\((?[^,)]+),?(?[^)]*)\)$/ .match(ret[:id]) or return ret id = if m[:id].empty? if m[:type] == "attachment" @@ -96,7 +97,7 @@ def analyse_ref_repo_path(ret) else m[:key].sub(%r{^[^/]+/}, "") end else m[:id] end - ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true) + ret.merge(id:, type: m[:type], key: m[:key], nofetch: true) end def analyse_ref_numeric(ret) diff --git a/lib/metanorma/standoc/section.rb b/lib/metanorma/standoc/section.rb index 1abbd118..f03b6b47 100644 --- a/lib/metanorma/standoc/section.rb +++ b/lib/metanorma/standoc/section.rb @@ -14,8 +14,8 @@ def sectiontype1(node) node.attr("heading")&.downcase || node.title .gsub(%r{.*?}m, "") - .gsub(%r{]*>.*?}m, "") - .gsub(/<[^>]+>/, "") + .gsub(%r{]*>.*?}m, "") + .gsub(/<[^<>]+>/, "") .strip.downcase.sub(/\.$/, "") end diff --git a/spec/metanorma/base_spec.rb b/spec/metanorma/base_spec.rb index 27efc4af..e686ac03 100644 --- a/spec/metanorma/base_spec.rb +++ b/spec/metanorma/base_spec.rb @@ -1378,7 +1378,7 @@ :scripts: spec/assets/scripts.html INPUT html = File.read("test.html", encoding: "utf-8") - expect(html).to match(%r{