[gxml] XParser: Throw error on incorrect node name
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] XParser: Throw error on incorrect node name
- Date: Sat, 5 Nov 2016 02:47:49 +0000 (UTC)
commit 6f41c293e4ba7993d18fe067b2636944ccd49f74
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Nov 4 20:44:03 2016 -0600
XParser: Throw error on incorrect node name
Parsing a DomElement with a different name from
expected, throws error
gxml/XParser.vala | 8 ++++++++
test/GomSerializationTest.vala | 8 ++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index 109a375..f284984 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -131,6 +131,14 @@ public class GXml.XParser : Object, GXml.Parser {
break;
case Xml.ReaderType.ELEMENT:
bool isempty = (tr.is_empty_element () == 1);
+ if (node is DomElement) {
+ if (read_current
+ && tr.const_local_name ().down ()
+ != (node as DomElement).local_name.down ())
+ throw new DomError.VALIDATION_ERROR
+ (_("Invalid element node name. Expected %s")
+ .printf ((node as DomElement).local_name));
+ }
if (node is DomDocument || !read_current) {
#if DEBUG
if (isempty) GLib.message ("Is Empty node:"+node.node_name);
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index d6cf18d..f6423a5 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -135,5 +135,13 @@ class GomSerializationTest : GXmlTest {
s = b.to_string ();
assert ("<Book Name=\"My Book\"/>" in s);
});
+ Test.add_func ("/gxml/gom-serialization/read/bad-node-name", () => {
+ var b = new Book ();
+ var parser = new XParser (b);
+ try {
+ parser.read_string ("<Chair name=\"Tall\"/>", null);
+ assert_not_reached ();
+ } catch {}
+ });
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]