beagle r4588 - in trunk/beagle: Util beagled



Author: dbera
Date: Sat Mar  8 14:47:09 2008
New Revision: 4588
URL: http://svn.gnome.org/viewvc/beagle?rev=4588&view=rev

Log:
Add a UriFu method to take a user supplied unescaped uri and change it to beagle specific uri (path and fragment escaped). Use this to suitably set the correct uri in DumpIndex and QueryParser (the two places where we take uri as a string from the user).


Modified:
   trunk/beagle/Util/UriFu.cs
   trunk/beagle/beagled/DumpIndex.cs
   trunk/beagle/beagled/QueryStringParser.cs

Modified: trunk/beagle/Util/UriFu.cs
==============================================================================
--- trunk/beagle/Util/UriFu.cs	(original)
+++ trunk/beagle/Util/UriFu.cs	Sat Mar  8 14:47:09 2008
@@ -97,6 +97,42 @@
 			return builder.ToString ();
 		}
 
+		// Get a uri of our liking from a user-entered uri
+		// Basically hex-escape the path, query and the fragment
+		static public Uri UserUritoEscapedUri (string user_uri)
+		{
+			Uri uri;
+			try {
+				uri = new Uri (user_uri);
+			} catch {
+				return null;
+			}
+
+			UriBuilder new_uri = new UriBuilder ();
+			new_uri.Scheme = uri.Scheme;
+			new_uri.Host = uri.Host;
+
+			if (uri.UserInfo != String.Empty) {
+				int index = uri.UserInfo.IndexOf (":");
+				if (index == -1)
+					new_uri.UserName = uri.UserInfo;
+				else {
+					new_uri.UserName = uri.UserInfo.Substring (0, index);
+					index ++;
+					if (index < uri.UserInfo.Length)
+						new_uri.Password = uri.UserInfo.Substring (index);
+				}
+			}
+
+			if (! uri.IsDefaultPort)
+				new_uri.Port = uri.Port;
+			new_uri.Path = StringFu.HexEscape (uri.AbsolutePath);
+			new_uri.Query = uri.Query; // FIXME: escape ?
+			new_uri.Fragment = StringFu.HexEscape (uri.Fragment);
+
+			return new_uri.Uri;
+		}
+
 		//////////////////////////////////
 
 		static public bool Equals (Uri uri1, Uri uri2)

Modified: trunk/beagle/beagled/DumpIndex.cs
==============================================================================
--- trunk/beagle/beagled/DumpIndex.cs	(original)
+++ trunk/beagle/beagled/DumpIndex.cs	Sat Mar  8 14:47:09 2008
@@ -393,9 +393,9 @@
 					Uri uri;
 					
 					try {
-						uri = new Uri (arg);
+						uri = UriFu.UserUritoEscapedUri (arg);
 					} catch (UriFormatException) {
-						uri = new Uri (Path.GetFullPath (arg));
+						uri = UriFu.PathToFileUri (arg);
 					}
 
 					uris.Add (uri);

Modified: trunk/beagle/beagled/QueryStringParser.cs
==============================================================================
--- trunk/beagle/beagled/QueryStringParser.cs	(original)
+++ trunk/beagle/beagled/QueryStringParser.cs	Sat Mar  8 14:47:09 2008
@@ -216,7 +216,7 @@
 				try {
 					QueryPart_Uri part = new QueryPart_Uri ();
 					part.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required);
-					part.Uri = UriFu.EscapedStringToUri (text);
+					part.Uri = UriFu.UserUritoEscapedUri (text);
 					return part;
 				} catch (System.UriFormatException) {
 					Log.Warn ("Could not parse [{0}] as uri query. Assuming text.", text);



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