[rygel] core: Check and escape URI in CreateObject



commit 94903755b250bfccb1bd6e371eb001a5ea1941a2
Author: Jens Georg <mail jensge org>
Date:   Tue Sep 27 16:03:12 2011 +0200

    core: Check and escape URI in CreateObject

 src/rygel/rygel-item-creator.vala |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)
---
diff --git a/src/rygel/rygel-item-creator.vala b/src/rygel/rygel-item-creator.vala
index 33c5e4f..5e98ee6 100644
--- a/src/rygel/rygel-item-creator.vala
+++ b/src/rygel/rygel-item-creator.vala
@@ -162,8 +162,9 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
                     }
                 }
 
-                if (this.is_valid_uri (resource.uri)) {
-                    this.item.add_uri (resource.uri);
+                string sanitized_uri;
+                if (this.is_valid_uri (resource.uri, out sanitized_uri)) {
+                    this.item.add_uri (sanitized_uri);
                 }
 
                 if (resource.size >= 0) {
@@ -354,21 +355,20 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
         }
     }
 
-    // FIXME: This function is hardly completely. Perhaps we should just make
-    // use of a regex here.
-    private bool is_valid_uri (string? uri) {
+    private bool is_valid_uri (string? uri, out string sanitized_uri) {
+        sanitized_uri = null;
         if (uri == null || uri == "") {
             return false;
         }
 
-        for (var next = uri.next_char ();
-             next != "";
-             next = next.next_char ()) {
-            if (next.get_char ().isspace ()) {
-                return false;
-            }
+        var soup_uri = new Soup.URI (uri);
+
+        if (soup_uri == null || soup_uri.scheme == null) {
+            return false;
         }
 
+        sanitized_uri = soup_uri.to_string (false);
+
         return true;
     }
 



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