[banshee] [Hyena.Query] Fix file location queries (bgo#612152)



commit f1d295d2b05a13b24e900ceb6392ce32568d691f
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Mon Mar 8 21:33:45 2010 +1100

    [Hyena.Query] Fix file location queries (bgo#612152)
    
    Signed-off-by: Alexander Kojevnikov <alexander kojevnikov com>

 .../Banshee.Services/Banshee.Query/BansheeQuery.cs |    2 +-
 .../Hyena/Hyena.Query/ExactStringQueryValue.cs     |    6 +++-
 .../Hyena/Hyena.Query/ExactUriStringQueryValue.cs  |   37 ++++++++++++++++++++
 .../Hyena/Hyena.Query/Tests/QueryTests.cs          |   24 +++++++++---
 src/Libraries/Hyena/Hyena.csproj                   |    1 +
 src/Libraries/Hyena/Makefile.am                    |    1 +
 6 files changed, 63 insertions(+), 8 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs b/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
index 28f366f..890f3d6 100644
--- a/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
+++ b/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
@@ -259,7 +259,7 @@ namespace Banshee.Query
 
         public static QueryField UriField = new QueryField (
             "uri", "Uri",
-            Catalog.GetString ("File Location"), "CoreTracks.Uri", typeof(ExactStringQueryValue),
+            Catalog.GetString ("File Location"), "CoreTracks.Uri", typeof(ExactUriStringQueryValue),
             // Translators: These are unique search fields. You can use CSV for synonyms. Please, no spaces. Blank ok.
             Catalog.GetString ("uri"), Catalog.GetString ("path"), Catalog.GetString ("file"), Catalog.GetString ("location"),
             "uri", "path", "file", "location"
diff --git a/src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs b/src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs
index 407173e..064cf70 100644
--- a/src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs
+++ b/src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs
@@ -33,7 +33,11 @@ namespace Hyena.Query
     {
         public override string ToSql (Operator op)
         {
-            return String.IsNullOrEmpty (value) ? null : EscapeString (op, value.ToLower ());
+            return String.IsNullOrEmpty (value) ? null : EscapeString (op, StringValue);
+        }
+
+        protected virtual string StringValue {
+            get { return value.ToLower (); }
         }
     }
 }
diff --git a/src/Libraries/Hyena/Hyena.Query/ExactUriStringQueryValue.cs b/src/Libraries/Hyena/Hyena.Query/ExactUriStringQueryValue.cs
new file mode 100644
index 0000000..221cace
--- /dev/null
+++ b/src/Libraries/Hyena/Hyena.Query/ExactUriStringQueryValue.cs
@@ -0,0 +1,37 @@
+//
+// ExactUriStringQueryValue.cs
+//
+// Authors:
+//   Andrés G. Aragoneses <knocte gmail com>
+//
+// 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;
+
+namespace Hyena.Query
+{
+    public class ExactUriStringQueryValue : ExactStringQueryValue
+    {
+        protected override string StringValue {
+            get { return System.Uri.EscapeUriString (base.StringValue); }
+        }
+    }
+}
diff --git a/src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs b/src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs
index ceb5c29..4fde91b 100644
--- a/src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs
+++ b/src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs
@@ -41,34 +41,34 @@ namespace Hyena.Query.Tests
     {
         private static QueryField ArtistField = new QueryField (
             "artist", "ArtistName", "Artist", "CoreArtists.NameLowered", true,
-            // Translators: These are unique search fields.  Please, no spaces. Blank ok.
             "by", "artist", "artists"
         );
 
         private static QueryField AlbumField = new QueryField (
             "album", "AlbumTitle", "Album", "CoreAlbums.TitleLowered", true,
-            // Translators: These are unique search fields.  Please, no spaces. Blank ok.
             "on", "album", "from", "albumtitle"
         );
 
         private static QueryField PlayCountField = new QueryField (
             "playcount", "PlayCount", "Play Count", "CoreTracks.PlayCount", typeof(IntegerQueryValue),
-            // Translators: These are unique search fields.  Please, no spaces. Blank ok.
             "plays", "playcount", "numberofplays", "listens"
         );
 
         private static QueryField DurationField = new QueryField (
             "duration", "Duration", "Duration", "CoreTracks.Duration", typeof(TimeSpanQueryValue),
-            // Translators: These are unique search fields.  Please, no spaces. Blank ok.
             "duration", "length", "time"
         );
 
         private static QueryField MimeTypeField = new QueryField (
             "mimetype", "MimeType", "Mime Type", "CoreTracks.MimeType {0} OR CoreTracks.Uri {0}", typeof(ExactStringQueryValue),
-            // Translators: These are unique search fields.  Please, no spaces. Blank ok.
             "type", "mimetype", "format", "ext", "mime"
         );
 
+        private static QueryField UriField = new QueryField (
+            "uri", "Uri", "File Location", "CoreTracks.Uri", typeof(ExactUriStringQueryValue),
+            "uri", "path", "file", "location"
+        );
+
         private static QueryFieldSet FieldSet = new QueryFieldSet (
             ArtistField, AlbumField, PlayCountField, MimeTypeField, DurationField
         );
@@ -219,7 +219,19 @@ namespace Hyena.Query.Tests
                 MimeTypeField.ToSql (StringQueryValue.Contains, val)
             );
         }
-		
+
+        [Test] // http://bugzilla.gnome.org/show_bug.cgi?id=612152
+        public void EscapeUri ()
+        {
+            QueryValue val = new ExactUriStringQueryValue ();
+            val.ParseUserQuery ("space 3quotes`'\"underscore_percentage%slash/backslash\\");
+
+            Assert.AreEqual (
+                @"(CoreTracks.Uri LIKE '%space\%203quotes\%60''\%22underscore\_percentage\%25slash/backslash\%5C%' ESCAPE '\' AND CoreTracks.Uri IS NOT NULL)",
+                UriField.ToSql (StringQueryValue.Contains, val)
+            );
+        }
+
         [Test]
         // Test behavior issues described in
         // http://bugzilla.gnome.org/show_bug.cgi?id=547078
diff --git a/src/Libraries/Hyena/Hyena.csproj b/src/Libraries/Hyena/Hyena.csproj
index 266f4be..2d630fb 100644
--- a/src/Libraries/Hyena/Hyena.csproj
+++ b/src/Libraries/Hyena/Hyena.csproj
@@ -175,6 +175,7 @@
     <Compile Include="Hyena.Json\Tests\SerializerTests.cs" />
     <Compile Include="Hyena.Json\Serializer.cs" />
     <Compile Include="Hyena\Tests\DateTimeUtilTests.cs" />
+    <Compile Include="Hyena.Query\ExactUriStringQueryValue.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
diff --git a/src/Libraries/Hyena/Makefile.am b/src/Libraries/Hyena/Makefile.am
index d771c9a..6ebf904 100644
--- a/src/Libraries/Hyena/Makefile.am
+++ b/src/Libraries/Hyena/Makefile.am
@@ -80,6 +80,7 @@ SOURCES =  \
 	Hyena.Query/DateQueryValue.cs \
 	Hyena.Query/EnumQueryValue.cs \
 	Hyena.Query/ExactStringQueryValue.cs \
+	Hyena.Query/ExactUriStringQueryValue.cs \
 	Hyena.Query/FileSizeQueryValue.cs \
 	Hyena.Query/IntegerKeyedObjectQueryValue.cs \
 	Hyena.Query/IntegerQueryValue.cs \



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