[tracker] tracker-search-tool: Added escaping for sparql



commit 2278226f5f01df9b488bece1f056934c9b8b147d
Author: Jamie McCracken <jamiemcc gnome org>
Date:   Thu Sep 24 23:53:23 2009 -0400

    tracker-search-tool: Added escaping for sparql

 src/tracker-search-tool/tracker-entry.gs |    4 ++--
 src/tracker-search-tool/tracker-query.gs |    8 +++++++-
 src/tracker-search-tool/tracker-utils.gs |   25 +++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/src/tracker-search-tool/tracker-entry.gs b/src/tracker-search-tool/tracker-entry.gs
index 6be1084..e928750 100644
--- a/src/tracker-search-tool/tracker-entry.gs
+++ b/src/tracker-search-tool/tracker-entry.gs
@@ -2,10 +2,10 @@
 
 uses
     Gtk
+    TrackerUtils
     
     
 class TrackerSearchEntry  : Gtk.Entry
-
     prop Query : TrackerQuery 
 
     init
@@ -27,7 +27,7 @@ class TrackerSearchEntry  : Gtk.Entry
                 Query.SearchTerms = ""
             else
                 set_icon_sensitive (EntryIconPosition.SECONDARY, true)
-                Query.SearchTerms = text
+                Query.SearchTerms = EscapeSparql (text)
         
     
     
diff --git a/src/tracker-search-tool/tracker-query.gs b/src/tracker-search-tool/tracker-query.gs
index fd07c11..6e66d60 100644
--- a/src/tracker-search-tool/tracker-query.gs
+++ b/src/tracker-search-tool/tracker-query.gs
@@ -55,7 +55,13 @@ class TrackerQuery : Object
             query = "SELECT ?s WHERE { ?s fts:match \"%s\". ?s a %s} limit 100 ".printf(SearchTerms, Category)   
 
         // to do : add Fields, Category and SortField
-        return tracker.SparqlQuery (query)
+        try
+            return tracker.SparqlQuery (query)
+        except e:DBus.Error
+            print "Dbus error : %s", e.message
+            
+        return null    
+
 
         
     def Query (sparql : string) : array of string[,] 
diff --git a/src/tracker-search-tool/tracker-utils.gs b/src/tracker-search-tool/tracker-utils.gs
index f04a782..09b0488 100644
--- a/src/tracker-search-tool/tracker-utils.gs
+++ b/src/tracker-search-tool/tracker-utils.gs
@@ -2,6 +2,7 @@
 
 uses
     Gtk
+
     
 
 enum Categories
@@ -30,6 +31,30 @@ const  extern static  SRCDIR : string
 class TrackerUtils
 /* static methods only as this is a utility class that wont ever get substantiated */
 
+    def static EscapeSparql (sparql : string) : string
+        var str = new StringBuilder ()
+        
+        if sparql is null
+            return ""
+            
+        var len = sparql.length   
+        
+        if len < 3 
+            return sparql    
+        
+        p : char*  = sparql
+
+        while *p is not '\0'
+            if *p is '"'
+                str.append ("\\\"")
+            else if *p is '\\'
+                str.append ("\\\\")
+            else
+                str.append_c (*p)
+            p++
+
+        return str.str
+		
 
 
 



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