util.xmppstream: Perfom validation of XML declaration parameters
authorMatthew Wild <mwild1@gmail.com>
Wed, 11 Jul 2018 11:57:42 +0100
changeset 9023 19e51d8f8947
parent 9022 d780c10709c1
child 9024 548ba4090012
util.xmppstream: Perfom validation of XML declaration parameters
util/xmppstream.lua
--- a/util/xmppstream.lua	Wed Jul 11 12:05:06 2018 +0200
+++ b/util/xmppstream.lua	Wed Jul 11 11:57:42 2018 +0100
@@ -130,16 +130,7 @@
 			t_insert(oldstanza.tags, stanza);
 		end
 	end
-	if lxp_supports_xmldecl then
-		function xml_handlers:XmlDecl(version, encoding, standalone)
-			session.xml_version = version;
-			session.xml_encoding = encoding;
-			session.xml_standalone = standalone;
-			if lxp_supports_bytecount then
-				cb_handleprogress(self:getcurrentbytecount());
-			end
-		end
-	end
+
 	function xml_handlers:StartCdataSection()
 		if lxp_supports_bytecount then
 			if stanza then
@@ -210,6 +201,18 @@
 		end
 	end
 
+	if lxp_supports_xmldecl then
+		function xml_handlers:XmlDecl(version, encoding, standalone)
+			if lxp_supports_bytecount then
+				cb_handleprogress(self:getcurrentbytecount());
+			end
+			if (encoding and encoding:lower() ~= "utf-8")
+			or (standalone == "no")
+			or (version and version ~= "1.0") then
+				return restricted_handler(self);
+			end
+		end
+	end
 	if lxp_supports_doctype then
 		xml_handlers.StartDoctypeDecl = restricted_handler;
 	end