[gxml] DomParentNode.query_selector() fix return element no found



commit 3d83964f3351f6a2d189a2f939a278340bee93e3
Author: Yannick Inizan <inizan yannick gmail com>
Date:   Thu Oct 12 17:44:06 2017 -0500

    DomParentNode.query_selector() fix return element no found
    
    DomParentNode.query_selector() checks if no elements are found
    and returns null. Return first found instead.

 gxml/DomCollections.vala |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/gxml/DomCollections.vala b/gxml/DomCollections.vala
index d6425e2..c103d99 100644
--- a/gxml/DomCollections.vala
+++ b/gxml/DomCollections.vala
@@ -32,7 +32,10 @@ public interface GXml.DomParentNode : GLib.Object {
   public abstract int child_element_count { get; }
 
   public virtual DomElement? query_selector (string selectors) throws GLib.Error {
-    return query_selector_all (selectors).item (0) as DomElement;
+    var list = query_selector_all (selectors);
+    if (list.size == 0)
+      return null;
+    return list.item (0) as DomElement;
   }
   public abstract DomNodeList query_selector_all (string selectors) throws GLib.Error;
   /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]