[hyena] Fix file location queries (bgo#612152)



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

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

 src/Hyena/Hyena.Query/ExactStringQueryValue.cs    |    6 +++-
 src/Hyena/Hyena.Query/ExactUriStringQueryValue.cs |   37 +++++++++++++++++++++
 src/Hyena/Hyena.Query/Tests/QueryTests.cs         |   24 ++++++++++---
 src/Hyena/Hyena.csproj                            |    1 +
 src/Hyena/Makefile.am                             |    1 +
 5 files changed, 62 insertions(+), 7 deletions(-)
---
diff --git a/src/Hyena/Hyena.Query/ExactStringQueryValue.cs b/src/Hyena/Hyena.Query/ExactStringQueryValue.cs
index 407173e..064cf70 100644
--- a/src/Hyena/Hyena.Query/ExactStringQueryValue.cs
+++ b/src/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/Hyena/Hyena.Query/ExactUriStringQueryValue.cs b/src/Hyena/Hyena.Query/ExactUriStringQueryValue.cs
new file mode 100644
index 0000000..221cace
--- /dev/null
+++ b/src/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/Hyena/Hyena.Query/Tests/QueryTests.cs b/src/Hyena/Hyena.Query/Tests/QueryTests.cs
index ceb5c29..4fde91b 100644
--- a/src/Hyena/Hyena.Query/Tests/QueryTests.cs
+++ b/src/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/Hyena/Hyena.csproj b/src/Hyena/Hyena.csproj
index 54ee63e..ab13cd0 100644
--- a/src/Hyena/Hyena.csproj
+++ b/src/Hyena/Hyena.csproj
@@ -162,6 +162,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/Hyena/Makefile.am b/src/Hyena/Makefile.am
index f631f9f..8dba339 100644
--- a/src/Hyena/Makefile.am
+++ b/src/Hyena/Makefile.am
@@ -109,6 +109,7 @@ SOURCES =  \
 	Hyena/Delegates.cs \
 	Hyena.Collections/LruCache.cs \
 	Hyena.Query/ExactStringQueryValue.cs \
+	Hyena.Query/ExactUriStringQueryValue.cs \
 	Hyena.Jobs/Job.cs \
 	Hyena.Jobs/JobExtensions.cs \
 	Hyena.Jobs/PriorityHints.cs \



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