summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2011-09-22 15:24:30 +0200
committerJens Georg <mail@jensge.org>2011-09-22 15:26:08 +0200
commitb9e8bcd491e74e554ff1752e7077f4c6ff7d5997 (patch)
tree56be43394e78c19c15fa123eef1cd3c9ad47286b
parente51b3b94545234b8ad8226d5db5ee552bd2c4c6b (diff)
downloadrygel-b9e8bcd491e74e554ff1752e7077f4c6ff7d5997.tar.gz
core: Mangle invalid characters in CreateItem
Do not fail if the upload directory is on a FAT file-system and the title contains characters that are invalid on FAT.
-rw-r--r--src/rygel/rygel-item-creator.vala19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/rygel/rygel-item-creator.vala b/src/rygel/rygel-item-creator.vala
index 5ed384bf..cabcbe0e 100644
--- a/src/rygel/rygel-item-creator.vala
+++ b/src/rygel/rygel-item-creator.vala
@@ -33,6 +33,8 @@ private errordomain Rygel.ItemCreatorError {
internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
private static PatternSpec comment_pattern = new PatternSpec ("*<!--*-->*");
+ private const string INVALID_CHARS = "/?<>\\:*|\"";
+
// In arguments
public string container_id;
public string elements;
@@ -44,6 +46,7 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
private ServiceAction action;
private DIDLLiteWriter didl_writer;
private DIDLLiteParser didl_parser;
+ private Regex title_regex;
public Cancellable cancellable { get; set; }
@@ -54,6 +57,12 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
this.action = (owned) action;
this.didl_writer = new DIDLLiteWriter (null);
this.didl_parser = new DIDLLiteParser ();
+ try {
+ var pattern = "[" + Regex.escape_string (INVALID_CHARS) + "]";
+ this.title_regex = new Regex (pattern,
+ RegexCompileFlags.OPTIMIZE,
+ RegexMatchFlags.NOTEMPTY);
+ } catch (Error error) { } /* ignore */
}
public async void run () {
@@ -363,6 +372,14 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
return true;
}
+ private string mangle_title (string title) throws Error {
+ return this.title_regex.replace_literal (title,
+ -1,
+ 0,
+ "_",
+ RegexMatchFlags.NOTEMPTY);
+ }
+
private async string create_uri (WritableContainer container, string title)
throws Error {
var dir = yield container.get_writable (this.cancellable);
@@ -373,7 +390,7 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
}
var now = new GLib.DateTime.now_utc ();
- var file = dir.get_child_for_display_name (title);
+ var file = dir.get_child_for_display_name (this.mangle_title (title));
return file.get_uri () + now.format ("%s");
}