[patch] bugfix for strip_password
- From: Jindrich Makovicka <makovick kmlinux fjfi cvut cz>
- To: MC Devel <mc-devel gnome org>
- Subject: [patch] bugfix for strip_password
- Date: Thu, 26 Aug 2004 10:22:59 +0200
Hi,
In current mc, strip_password misbehaves for URLs like
/#ftp:user:pass hostname/path/path/path
which makes mc display only the string in the form
/#ftp:user hostname
in the title bar, instead of (IMHO correct)
/#ftp:user hostname/path/path/path
The attached patch attempts to re-implement the function with the
correct behavior.
--
Jindrich Makovicka
diff --exclude-from dontdiff -urN vanilla/mc/src/util.c mc/src/util.c
--- vanilla/mc/src/util.c 2004-08-17 17:51:30.000000000 +0200
+++ mc/src/util.c 2004-08-17 17:56:02.000000000 +0200
@@ -409,9 +409,8 @@
{"ftp://", 6},
{"/#smb:", 6},
};
- char *at, *inner_colon, *dir;
+ char *at, *inner_colon, *tmp;
size_t i;
- char *result = p;
for (i = 0; i < sizeof (prefixes)/sizeof (prefixes[0]); i++) {
char *q;
@@ -420,27 +419,28 @@
if((q = strstr (p, prefixes[i].name)) == 0)
continue;
else
- p = q + prefixes[i].len;
+ tmp = q + prefixes[i].len;
+ } else {
+ tmp = p;
};
- if ((dir = strchr (p, PATH_SEP)) != NULL)
- *dir = '\0';
- /* search for any possible user */
- at = strchr (p, '@');
-
- /* We have a username */
- if (at) {
- *at = 0;
- inner_colon = strchr (p, ':');
- *at = '@';
- if (inner_colon)
- strcpy (inner_colon, at);
+ inner_colon = 0;
+ at = 0;
+ while (*tmp) {
+ if (*tmp == PATH_SEP) break; /* path separator */
+ if (*tmp == ':' && !inner_colon) inner_colon = tmp;
+ if (*tmp == '@' && !at) {
+ at = tmp;
+ break;
}
- if (dir)
- *dir = PATH_SEP;
+ tmp++;
+ }
+ if (at && inner_colon) {
+ memmove(inner_colon, at, strlen(at)+1);
break;
}
- return (result);
+ }
+ return (p);
}
char *strip_home_and_password(const char *dir)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]