From ea44eaac1cc768e569b7ee4ec3c03fba05c7c683 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Mon, 28 Nov 2011 22:45:31 +0100 Subject: [PATCH] Feature #881 * Output of URIs (during merge, pull, push) now omits passwords. --- src/Uri.cpp | 24 ++++++++++++++++++++++++ src/Uri.h | 1 + src/commands/CmdMerge.cpp | 2 +- src/commands/CmdPull.cpp | 2 +- src/commands/CmdPush.cpp | 2 +- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Uri.cpp b/src/Uri.cpp index d105343ae..e5283c8f6 100644 --- a/src/Uri.cpp +++ b/src/Uri.cpp @@ -189,6 +189,30 @@ bool Uri::expand (const std::string& configPrefix ) return false; } +//////////////////////////////////////////////////////////////////////////////// +std::string Uri::ToString () +{ + if (!_parsed) + return std::string (); + + std::string result; + // strip password from _user + std::string::size_type pos = _user.find (":"); + result = _protocol + "://"; + + if (_user.length () > 0) + result += _user.substr (0, pos) + "@"; + + result += _host; + + if (_port.length () > 0) + result += + ":" + _port; + + result += "/" + _path; + + return result; +} + //////////////////////////////////////////////////////////////////////////////// void Uri::parse () { diff --git a/src/Uri.h b/src/Uri.h index 995dd9f50..de1dd0027 100644 --- a/src/Uri.h +++ b/src/Uri.h @@ -51,6 +51,7 @@ public: std::string name () const; std::string parent () const; std::string extension () const; + std::string ToString(); bool is_directory () const; bool is_local () const; bool append (const std::string&); diff --git a/src/commands/CmdMerge.cpp b/src/commands/CmdMerge.cpp index 5bea0e27a..dc717c199 100644 --- a/src/commands/CmdMerge.cpp +++ b/src/commands/CmdMerge.cpp @@ -97,7 +97,7 @@ int CmdMerge::execute (std::string& output) if (tmpfile != "") remove (tmpfile.c_str ()); - if (((sAutopush == "ask") && (confirm (format (STRING_CMD_MERGE_CONFIRM, uri._data)))) + if (((sAutopush == "ask") && (confirm (format (STRING_CMD_MERGE_CONFIRM, uri.ToString ())))) || (bAutopush)) { // Derive autopush uri from merge.default.uri? otherwise: change prompt above diff --git a/src/commands/CmdPull.cpp b/src/commands/CmdPull.cpp index c2f0816f7..135778380 100644 --- a/src/commands/CmdPull.cpp +++ b/src/commands/CmdPull.cpp @@ -112,7 +112,7 @@ int CmdPull::execute (std::string& output) } } - output += format (STRING_CMD_PULL_TRANSFERRED, uri._data) + "\n"; + output += format (STRING_CMD_PULL_TRANSFERRED, uri.ToString ()) + "\n"; } else throw std::string (STRING_CMD_PULL_NO_URI); diff --git a/src/commands/CmdPush.cpp b/src/commands/CmdPush.cpp index 60c611050..7e829a0b6 100644 --- a/src/commands/CmdPush.cpp +++ b/src/commands/CmdPush.cpp @@ -96,7 +96,7 @@ int CmdPush::execute (std::string& output) ofile3 << ifile3.rdbuf(); } - output += format (STRING_CMD_PUSH_TRANSFERRED, uri._data) + "\n"; + output += format (STRING_CMD_PUSH_TRANSFERRED, uri.ToString ()) + "\n"; } else throw std::string (STRING_CMD_PUSH_NO_URI);