[hyena] Query: fix FileLocation queries for the StartsWith operator



commit 97ee220f0f9ba3b7422148d91887fa4dae4839f2
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Sun Dec 11 20:43:57 2011 +0000

    Query: fix FileLocation queries for the StartsWith operator
    
    In the same way user queries were already being escaped [1] so
    the user didn't need to do it manually (i.e. when creating a
    Smart Playlist in Banshee), hyena should be smart enough to add
    the file scheme to the value queried in case the operator
    StartsWith is used, so the Uri is correctly formed in the LIKE
    filter. Fixes bgo#644145.
    
    [1] http://mail.gnome.org/archives/commits-list/2010-March/msg02864.html

 Hyena/Hyena.Query/ExactStringQueryValue.cs    |    6 +-----
 Hyena/Hyena.Query/ExactUriStringQueryValue.cs |   17 +++++++++++++----
 Hyena/Hyena.Query/Tests/QueryTests.cs         |   13 +++++++++++++
 3 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/Hyena/Hyena.Query/ExactStringQueryValue.cs b/Hyena/Hyena.Query/ExactStringQueryValue.cs
index 28da5bc..1fddeea 100644
--- a/Hyena/Hyena.Query/ExactStringQueryValue.cs
+++ b/Hyena/Hyena.Query/ExactStringQueryValue.cs
@@ -35,11 +35,7 @@ namespace Hyena.Query
     {
         public override string ToSql (Operator op)
         {
-            return String.IsNullOrEmpty (value) ? null : EscapeString (op, StringValue);
-        }
-
-        protected virtual string StringValue {
-            get { return value.ToLower (); }
+            return String.IsNullOrEmpty (value) ? null : EscapeString (op, value.ToLower ());
         }
     }
 }
diff --git a/Hyena/Hyena.Query/ExactUriStringQueryValue.cs b/Hyena/Hyena.Query/ExactUriStringQueryValue.cs
index 01640c7..01c2e89 100644
--- a/Hyena/Hyena.Query/ExactUriStringQueryValue.cs
+++ b/Hyena/Hyena.Query/ExactUriStringQueryValue.cs
@@ -4,7 +4,7 @@
 // Authors:
 //   AndrÃs G. Aragoneses <knocte gmail com>
 //
-// Copyright (C) 2010 AndrÃs G. Aragoneses
+// Copyright (C) 2010-2011 AndrÃs G. Aragoneses
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -32,8 +32,17 @@ namespace Hyena.Query
 {
     public class ExactUriStringQueryValue : ExactStringQueryValue
     {
-        protected override string StringValue {
-            get { return Uri.EscapeUriString (base.StringValue); }
-        }
+        public override string ToSql (Operator op)
+        {
+            if (String.IsNullOrEmpty (value)) {
+                return null;
+            }
+
+            string escaped_value = EscapeString (op, Uri.EscapeUriString (value.ToLower ()));
+            if (op == StartsWith) {
+                return "file://" + escaped_value;
+            }
+            return escaped_value;
+         }
     }
 }
diff --git a/Hyena/Hyena.Query/Tests/QueryTests.cs b/Hyena/Hyena.Query/Tests/QueryTests.cs
index ff0a470..bc3e71d 100644
--- a/Hyena/Hyena.Query/Tests/QueryTests.cs
+++ b/Hyena/Hyena.Query/Tests/QueryTests.cs
@@ -232,6 +232,19 @@ namespace Hyena.Query.Tests
             );
         }
 
+        [Test] // http://bugzilla.gnome.org/show_bug.cgi?id=644145
+        public void EscapeUriWithStartsWithOperator ()
+        {
+            QueryValue val = new ExactUriStringQueryValue ();
+            val.ParseUserQuery ("/mnt/mydrive/rock & roll");
+
+            Assert.AreEqual (
+                @"(CoreTracks.Uri IS NOT NULL AND" + 
+                @" CoreTracks.Uri LIKE 'file:///mnt/mydrive/rock\%20&\%20roll%' ESCAPE '\')",
+                UriField.ToSql (StringQueryValue.StartsWith, val)
+            );
+        }
+
         [Test]
         // Test behavior issues described in
         // http://bugzilla.gnome.org/show_bug.cgi?id=547078



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