banshee r5076 - in trunk/banshee: . src/Libraries/Hyena/Hyena.Query src/Libraries/Hyena/Hyena.Query/Tests
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r5076 - in trunk/banshee: . src/Libraries/Hyena/Hyena.Query src/Libraries/Hyena/Hyena.Query/Tests
- Date: Thu, 26 Feb 2009 23:32:42 +0000 (UTC)
Author: gburt
Date: Thu Feb 26 23:32:42 2009
New Revision: 5076
URL: http://svn.gnome.org/viewvc/banshee?rev=5076&view=rev
Log:
2009-02-26 Gabriel Burt <gabriel burt gmail com>
* src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs:
* src/Libraries/Hyena/Hyena.Query/StringQueryValue.cs: Patch from AndrÃs
G. Aragoneses and John Millikin fixing the wildcard escaping
ExactStringQueryValues in LIKE queries (BGO #570312)
* src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs: New tests AndrÃs
testing the behavior for Exact and non LIKE queries.
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs
trunk/banshee/src/Libraries/Hyena/Hyena.Query/StringQueryValue.cs
trunk/banshee/src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Query/ExactStringQueryValue.cs Thu Feb 26 23:32:42 2009
@@ -33,7 +33,7 @@
{
public override string ToSql (Operator op)
{
- return String.IsNullOrEmpty (value) ? null : value.Replace ("'", "''").ToLower ();
+ return String.IsNullOrEmpty (value) ? null : EscapeString (op, value.ToLower ());
}
}
}
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Query/StringQueryValue.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Query/StringQueryValue.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Query/StringQueryValue.cs Thu Feb 26 23:32:42 2009
@@ -81,28 +81,21 @@
public override string ToSql (Operator op)
{
- if (String.IsNullOrEmpty (value))
- return null;
-
- string ret = null;
+ return String.IsNullOrEmpty (value) ? null : EscapeString (op, Hyena.StringUtil.SearchKey (value));
+ }
- // SearchKey() removes ' anyway, but it's escaped again so proper
- // SQL behavior isn't dependent on search behavior.
- ret = Hyena.StringUtil.SearchKey (value).Replace ("'", "''");
+ protected static string EscapeString (Operator op, string orig)
+ {
+ orig = orig.Replace ("'", "''");
if (op == Contains || op == DoesNotContain ||
op == StartsWith || op == EndsWith) {
- ret = EscapeLike (ret);
+ return orig.Replace ("\\", "\\\\")
+ .Replace ("%", "\\%")
+ .Replace ("_", "\\_");
}
-
- return ret;
- }
-
- private static string EscapeLike (string orig)
- {
- return orig.Replace ("\\", "\\\\")
- .Replace ("%", "\\%")
- .Replace ("_", "\\_");
+
+ return orig;
}
}
}
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs Thu Feb 26 23:32:42 2009
@@ -64,7 +64,7 @@
);
private static QueryField MimeTypeField = new QueryField (
- "mimetype", "MimeType", "Mime Type", "CoreTracks.MimeType {0} OR CoreTracks.Uri {0}",
+ "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"
);
@@ -157,6 +157,66 @@
MimeTypeField.ToSql (StringQueryValue.Contains, val)
);
}
+
+ [Test]
+ public void EscapeSingleQuotes ()
+ {
+ QueryValue val = new StringQueryValue ();
+ val.ParseUserQuery ("Kelli O'Hara");
+
+ Assert.AreEqual (
+ "(CoreArtists.NameLowered LIKE '%kelli ohara%' ESCAPE '\\' AND CoreArtists.NameLowered IS NOT NULL)",
+ ArtistField.ToSql (StringQueryValue.Contains, val)
+ );
+ }
+
+ [Test] // http://bugzilla.gnome.org/show_bug.cgi?id=570312
+ public void EscapeSqliteWildcards1 ()
+ {
+ QueryValue val = new StringQueryValue ();
+ val.ParseUserQuery ("100% Techno");
+
+ Assert.AreEqual (
+ "(CoreAlbums.TitleLowered LIKE '%100 techno%' ESCAPE '\\' AND CoreAlbums.TitleLowered IS NOT NULL)",
+ AlbumField.ToSql (StringQueryValue.Contains, val)
+ );
+ }
+
+ [Test] // http://bugzilla.gnome.org/show_bug.cgi?id=570312
+ public void EscapeSqliteWildcards2 ()
+ {
+ QueryValue val = new StringQueryValue ();
+ val.ParseUserQuery ("-_-");
+
+ Assert.AreEqual (
+ "(CoreAlbums.TitleLowered LIKE '%-\\_-%' ESCAPE '\\' AND CoreAlbums.TitleLowered IS NOT NULL)",
+ AlbumField.ToSql (StringQueryValue.Contains, val)
+ );
+ }
+
+ [Test] // http://bugzilla.gnome.org/show_bug.cgi?id=570312
+ public void EscapeSqliteWildcards3 ()
+ {
+ QueryValue val = new StringQueryValue ();
+ val.ParseUserQuery ("Metallic/\\");
+
+ Assert.AreEqual (
+ "(CoreAlbums.TitleLowered LIKE '%metallic%' ESCAPE '\\' AND CoreAlbums.TitleLowered IS NOT NULL)",
+ AlbumField.ToSql (StringQueryValue.Contains, val)
+ );
+ }
+
+ [Test] // http://bugzilla.gnome.org/show_bug.cgi?id=570312
+ public void EscapeSqliteWildcards4Real ()
+ {
+ QueryValue val = new ExactStringQueryValue ();
+ val.ParseUserQuery ("/\\_%`'");
+
+ Assert.AreEqual (
+ "(CoreTracks.MimeType LIKE '%/\\\\\\_\\%`''%' ESCAPE '\\' OR CoreTracks.Uri LIKE '%/\\\\\\_\\%`''%' ESCAPE '\\')",
+ MimeTypeField.ToSql (StringQueryValue.Contains, val)
+ );
+ }
[Test]
// Test behavior issues described in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]