scansion/stanzacmp.lua

changeset 153
f83ea6e5c3d8
parent 151
8191f165b9dd
child 170
db73c4c317ce
--- a/scansion/stanzacmp.lua	Thu Sep 13 16:05:45 2018 +0100
+++ b/scansion/stanzacmp.lua	Fri Sep 14 12:56:19 2018 +0100
@@ -11,8 +11,8 @@
 	return (s:gsub("^%s+", ""):gsub("%s+$", ""));
 end
 
-local function wants_strict(tag)
-	local opt = tag.attr["scansion:strict"] or "yes";
+local function wants_strict(tag, default)
+	local opt = tag.attr["scansion:strict"] or default or "yes";
 	if opt == "no" or opt == "false" or opt == "0" then
 		return false;
 	elseif opt == "yes" or opt == "true" or opt == "1" then
@@ -72,6 +72,9 @@
 -- Everything in stanza1 should be present in stanza2
 
 local function stanzas_match(stanza1, stanza2)
+	if wants_strict(stanza1, stanza1.attr.xmlns == nil and "no" or "yes") then
+		return stanzas_strict_match(stanza1, stanza2);
+	end
 	if stanza1.name ~= stanza2.name or stanza1.attr.xmlns ~= stanza2.attr.xmlns then
 		return false;
 	end
@@ -95,12 +98,7 @@
 
 					if type(child2) == type(child) then
 						if type(child) == "table" and child2.name == child.name and child2.attr.xmlns == child.attr.xmlns then
-							if wants_strict(child) then
-								-- Strict deep match
-								match = stanzas_strict_match(child, child2);
-							else
-								match = stanzas_match(child, child2);
-							end
+							match = stanzas_match(child, child2);
 						elseif type(child) == "string" then -- Text nodes, must be equal, ignoring leading/trailing whitespace
 							match = trim(child) == trim(child2);
 						end

mercurial