Index: src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
===================================================================
--- src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	(revision 5038)
+++ src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	(working copy)
@@ -190,7 +190,7 @@
         public virtual SafeUri UriAndTypeToSafeUri (TrackUriType type, string uri_field)
         {
             if (type == TrackUriType.RelativePath && BaseDirectory != null)
-                return new SafeUri (System.IO.Path.Combine (BaseDirectory, uri_field));
+                return new SafeUri (System.IO.Path.Combine (BaseDirectory, Uri.UnescapeDataString (uri_field)));
             else
                 return new SafeUri (uri_field);
         }
@@ -201,6 +201,8 @@
             type = (uri_field == null) ? TrackUriType.AbsoluteUri : TrackUriType.RelativePath;
             if (uri_field == null) {
                 uri_field = uri.AbsoluteUri;
+            } else {
+                uri_field = Uri.EscapeUriString (uri_field);
             }
         }
 
Index: src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
===================================================================
--- src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs	(revision 5038)
+++ src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs	(working copy)
@@ -261,7 +261,7 @@
 
         public static QueryField UriField = new QueryField (
             "uri", "Uri",
-            Catalog.GetString ("File Location"), "CoreTracks.Uri", typeof(ExactStringQueryValue),
+            Catalog.GetString ("File Location"), "CoreTracks.Uri", typeof (UriQueryValue),
             // Translators: These are unique search fields.  Please, no spaces. Blank ok.
             Catalog.GetString ("uri"), Catalog.GetString ("path"), Catalog.GetString ("file"), Catalog.GetString ("location"),
             "uri", "path", "file", "location"
Index: src/Libraries/Hyena/Hyena.csproj
===================================================================
--- src/Libraries/Hyena/Hyena.csproj	(revision 5038)
+++ src/Libraries/Hyena/Hyena.csproj	(working copy)
@@ -137,6 +137,8 @@
     <Compile Include="Hyena.Json\Tests\DeserializerTests.cs" />
     <Compile Include="Hyena\Delegates.cs" />
     <Compile Include="Hyena.Collections\LruCache.cs" />
+    <Compile Include="Hyena.Query\UriQueryValue.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ProjectExtensions>
Index: src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs
===================================================================
--- src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs	(revision 5038)
+++ src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs	(working copy)
@@ -33,7 +33,13 @@
     {
         public override string ToSql (Operator op)
         {
-            return String.IsNullOrEmpty (value) ? null : value.Replace ("'", "''").ToLower ();
+            return String.IsNullOrEmpty (value) ? null : EscapeExact (value);
         }
+
+        protected static string EscapeExact (string val)
+        {
+            return val.Replace ("'", "''").ToLower ();
+        }
+
     }
 }
Index: src/Libraries/Hyena/Hyena.Query/UriQueryValue.cs
===================================================================
--- src/Libraries/Hyena/Hyena.Query/UriQueryValue.cs	(revision 0)
+++ src/Libraries/Hyena/Hyena.Query/UriQueryValue.cs	(revision 0)
@@ -0,0 +1,53 @@
+//
+// UriQueryValue.cs
+//
+// Authors:
+//   Andrés G. Aragoneses <aaragoneses@novell.com>
+//
+// Copyright (C) 2009 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+using Hyena;
+
+namespace Hyena.Query
+{
+    public class UriQueryValue : ExactStringQueryValue
+    {
+        public override string ToSql (Operator op)
+        {
+            if (String.IsNullOrEmpty (value))
+                return null;
+
+            string ret = Hyena.StringUtil.SearchKey (value);
+
+            ret = Uri.EscapeDataString (ret);
+
+            ret = EscapeLike (op, ret);
+
+            // SearchKey() removes ' anyway, but it's escaped again so proper
+            // SQL behavior isn't dependent on search behavior.
+            return EscapeExact (ret);
+        }
+    }
+}
Index: src/Libraries/Hyena/Hyena.Query/StringQueryValue.cs
===================================================================
--- src/Libraries/Hyena/Hyena.Query/StringQueryValue.cs	(revision 5038)
+++ src/Libraries/Hyena/Hyena.Query/StringQueryValue.cs	(working copy)
@@ -90,12 +90,18 @@
             // SQL behavior isn't dependent on search behavior.
             ret = Hyena.StringUtil.SearchKey (value).Replace ("'", "''");
 
+            ret = EscapeLike (op, ret);
+
+            return ret;
+        }
+
+        protected static string EscapeLike (Operator op, string val)
+        {
             if (op == Contains   || op == DoesNotContain ||
                 op == StartsWith || op == EndsWith) {
-                ret = EscapeLike (ret);
+                return EscapeLike (val);
             }
-
-            return ret;
+            return val;
         }
 
         private static string EscapeLike (string orig)
Index: src/Libraries/Hyena/Makefile.am
===================================================================
--- src/Libraries/Hyena/Makefile.am	(revision 5038)
+++ src/Libraries/Hyena/Makefile.am	(working copy)
@@ -78,6 +78,7 @@
 	Hyena.Query/StringQueryValue.cs \
 	Hyena.Query/Tests/QueryTests.cs \
 	Hyena.Query/TimeSpanQueryValue.cs \
+	Hyena.Query/UriQueryValue.cs \
 	Hyena.Query/UserQueryParser.cs \
 	Hyena.Query/XmlQueryParser.cs \
 	Hyena.SExpEngine/ArithmeticFunctionSet.cs \
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5038)
+++ ChangeLog	(working copy)
@@ -1,3 +1,24 @@
+2009-02-15  Andrés G. Aragoneses  <aaragoneses@novell.com>
+
+	Partial fix (still one case to remaining to close it) for BGO#564355.
+
+	* src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs: Use the new
+	type UriQueryValue for UriField.
+
+	* src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs: Make Uris
+	consistent in formatting (now they are escaped regardless if they are
+	relative or not).
+
+	* src/Libraries/Hyena/Hyena.csproj:
+	* src/Libraries/Hyena/Makefile.am: Add new file UriQueryValue.cs.
+
+	* src/Libraries/Hyena/ExactStringQueryValue.cs: 
+	* src/Libraries/Hyena/StringQueryValue.cs: Encapsulate the escaping
+	operations to be reused by derived classes.
+
+	* src/Libraries/Hyena/UriQueryValue.cs: New file to handle the
+	proper escaping for queries against Uris.
+
 2009-02-12  Gabriel Burt  <gabriel.burt@gmail.com>
 
 	* src/Core/Banshee.Core/Banshee.Base/Tests/FileNamePatternTests.cs: Remove
