[rygel] tracker: Properly escape regex in title containers
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] tracker: Properly escape regex in title containers
- Date: Wed, 13 Apr 2011 12:41:48 +0000 (UTC)
commit 09128c3392225847fed00cf8d5d20f8660d61461
Author: Jens Georg <mail jensge org>
Date: Tue Apr 12 17:29:53 2011 +0300
tracker: Properly escape regex in title containers
src/plugins/tracker/rygel-tracker-query.vala | 14 ++++++++++++++
.../tracker/rygel-tracker-search-container.vala | 2 +-
src/plugins/tracker/rygel-tracker-titles.vala | 2 +-
3 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-query.vala b/src/plugins/tracker/rygel-tracker-query.vala
index 29bd80f..4a66ac4 100644
--- a/src/plugins/tracker/rygel-tracker-query.vala
+++ b/src/plugins/tracker/rygel-tracker-query.vala
@@ -43,6 +43,20 @@ public abstract class Rygel.Tracker.Query {
}
/**
+ * Convenience function to combine Query.escape_string and
+ * Regex.escape_string in one function call
+ *
+ * @param literal A string to escape
+ *
+ * @return A newly allocated string with the sparql-escaped regex-escaped
+ * version of literal. The returned string should be freed with g_free()
+ * when no longer needed.
+ */
+ public static string escape_regex (string literal) {
+ return escape_string (Regex.escape_string (literal));
+ }
+
+ /**
* tracker_sparql_escape_string: Escapes a string so that it can be
* used in a SPARQL query. Copied from Tracker project.
*
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index cc9c600..21cd9b0 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -276,7 +276,7 @@ public class Rygel.Tracker.SearchContainer : Rygel.MediaContainer {
break;
case SearchCriteriaOp.CONTAINS:
// We need to escape this twice for Tracker
- var regex = Query.escape_string (Regex.escape_string (value));
+ var regex = Query.escape_regex (value);
filter = "regex(" + variable + ", \"" + regex + "\", \"i\")";
break;
diff --git a/src/plugins/tracker/rygel-tracker-titles.vala b/src/plugins/tracker/rygel-tracker-titles.vala
index 684d9e3..3e48d5c 100644
--- a/src/plugins/tracker/rygel-tracker-titles.vala
+++ b/src/plugins/tracker/rygel-tracker-titles.vala
@@ -74,7 +74,7 @@ public class Rygel.Tracker.Titles : MetadataValues {
}
protected override string create_filter (string variable, string value) {
- var title = this.create_title_for_value (value);
+ var title = Query.escape_regex (this.create_title_for_value (value));
return "regex(" + variable + ", \"^" + title + "\", \"i\")";
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]