summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-file-utilities.c
diff options
context:
space:
mode:
authorJohn Sullivan <sullivan@src.gnome.org>2000-11-17 22:08:45 +0000
committerJohn Sullivan <sullivan@src.gnome.org>2000-11-17 22:08:45 +0000
commitf7e57b538c48e7b2bb490beac9ffeff62fc0a4c9 (patch)
treeb4f0d71bcaebbee819deb6224aac50ed3636e326 /libnautilus-private/nautilus-file-utilities.c
parent288b3bda71bee86598618816a6e3f823ec82913e (diff)
downloadnautilus-f7e57b538c48e7b2bb490beac9ffeff62fc0a4c9.tar.gz
reviewed by: Mathieu Lacage <mathieu@eazel.com>
Fixed bug 4484 (leading whitespace in location bar produces errors) Fixed bug 4039 (Pasting URL with trailing carriage return fails, but needn't) * libnautilus-extensions/nautilus-file-utilities.c: (nautilus_make_uri_from_input): Strip leading and trailing white space before any further processing; also now handles NULL with return_val_if_fail. (nautilus_self_check_file_utilities): Added new self-check tests for white space stripping, and a couple of others.
Diffstat (limited to 'libnautilus-private/nautilus-file-utilities.c')
-rw-r--r--libnautilus-private/nautilus-file-utilities.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c
index 7aea86f6d..ac58afdc2 100644
--- a/libnautilus-private/nautilus-file-utilities.c
+++ b/libnautilus-private/nautilus-file-utilities.c
@@ -117,19 +117,26 @@ nautilus_format_uri_for_display (const char *uri)
char *
nautilus_make_uri_from_input (const char *location)
{
- char *path, *toreturn, *escaped;
+ char *stripped, *path, *toreturn, *escaped;
const char *no_method;
int method_length;
- if (location[0] == '/') {
- escaped = gnome_vfs_escape_path_string (location);
+ g_return_val_if_fail (location != NULL, g_strdup (""));
+
+ /* URIs can't contain leading or trailing white space,
+ * so strip it off. This makes copy/paste of URIs less error-prone.
+ */
+ stripped = g_strstrip (g_strdup (location));
+
+ if (stripped[0] == '/') {
+ escaped = gnome_vfs_escape_path_string (stripped);
toreturn = g_strconcat (DEFAULT_SCHEME, escaped, NULL);
g_free (escaped);
- } else if (location[0] == '~') {
- if (location[1] == '/') {
- path = g_strconcat (g_get_home_dir (), &location[1], NULL);
- } else if (location[1]) {
- path = g_strconcat ("/home/", &location[1], NULL);
+ } else if (stripped[0] == '~') {
+ if (stripped[1] == '/') {
+ path = g_strconcat (g_get_home_dir (), &stripped[1], NULL);
+ } else if (stripped[1]) {
+ path = g_strconcat ("/home/", &stripped[1], NULL);
} else {
path = g_strdup (g_get_home_dir ());
}
@@ -139,9 +146,9 @@ nautilus_make_uri_from_input (const char *location)
g_free (escaped);
} else {
- no_method = strchr (location, ':');
+ no_method = strchr (stripped, ':');
if (no_method == NULL) {
- no_method = location;
+ no_method = stripped;
} else {
no_method++;
if ((no_method[0] == '/') && (no_method[1] == '/')) {
@@ -149,15 +156,17 @@ nautilus_make_uri_from_input (const char *location)
}
}
- method_length = (no_method - location);
+ method_length = (no_method - stripped);
escaped = gnome_vfs_escape_host_and_path_string (no_method);
toreturn = g_new (char, strlen (escaped) + method_length + 1);
toreturn[0] = '\0';
- strncat (toreturn, location, method_length);
+ strncat (toreturn, stripped, method_length);
strcat (toreturn, escaped);
g_free (escaped);
}
+ g_free (stripped);
+
return toreturn;
}
@@ -1227,6 +1236,11 @@ nautilus_self_check_file_utilities (void)
{
/* nautilus_make_uri_from_input */
NAUTILUS_CHECK_STRING_RESULT (nautilus_make_uri_from_input (""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_make_uri_from_input ("/home"), "file:///home");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_make_uri_from_input ("www.eazel.com"), "www.eazel.com");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_make_uri_from_input (" "), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_make_uri_from_input (" \n\t"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_make_uri_from_input (" /home\n\n"), "file:///home");
NAUTILUS_CHECK_STRING_RESULT (nautilus_make_uri_from_input ("http://null.stanford.edu"), "http://null.stanford.edu");
NAUTILUS_CHECK_STRING_RESULT (nautilus_make_uri_from_input ("http://null.stanford.edu:80"), "http://null.stanford.edu:80");
NAUTILUS_CHECK_STRING_RESULT (nautilus_make_uri_from_input ("http://seth@null.stanford.edu:80"), "http://seth@null.stanford.edu:80");