# HG changeset patch # User jrice@netbeans.org # Date 1202325447 0 # Node ID 64509e0ef84ec9252fc08816299d8220d5715e94 # Parent 25c88ff0be07dc31f32fa753abed51dcaf8aae22 #126828: replace password text in push and pull paths and in error output with **** diff -r 25c88ff0be07 -r 64509e0ef84e mercurial/src/org/netbeans/modules/mercurial/ui/pull/FetchAction.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/pull/FetchAction.java Wed Feb 06 10:05:15 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/pull/FetchAction.java Wed Feb 06 19:17:27 2008 +0000 @@ -104,7 +104,7 @@ public class FetchAction extends Abstrac list = HgCommand.doFetch(root); if (list != null && !list.isEmpty()) { - HgUtils.outputMercurialTab(list); + HgUtils.outputMercurialTab(HgUtils.replaceHttpPassword(list)); } } catch (HgException ex) { NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex); diff -r 25c88ff0be07 -r 64509e0ef84e mercurial/src/org/netbeans/modules/mercurial/ui/pull/PullAction.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/pull/PullAction.java Wed Feb 06 10:05:15 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/pull/PullAction.java Wed Feb 06 19:17:27 2008 +0000 @@ -261,16 +261,16 @@ public class PullAction extends Abstract if (list != null && !list.isEmpty()) { if (!bNoChanges) { - annotateChangeSets(listIncoming, PullAction.class, "MSG_CHANGESETS_TO_PULL"); // NOI18N + annotateChangeSets(HgUtils.replaceHttpPassword(listIncoming), PullAction.class, "MSG_CHANGESETS_TO_PULL"); // NOI18N } - HgUtils.outputMercurialTab(list); + HgUtils.outputMercurialTab(HgUtils.replaceHttpPassword(list)); if (fromPrjName != null) { HgUtils.outputMercurialTabInRed(NbBundle.getMessage( - PullAction.class, "MSG_PULL_FROM", fromPrjName, HgUtils.stripDoubleSlash(pullPath))); // NOI18N + PullAction.class, "MSG_PULL_FROM", fromPrjName, HgUtils.stripDoubleSlash(HgUtils.replaceHttpPassword(pullPath)))); // NOI18N } else { HgUtils.outputMercurialTabInRed(NbBundle.getMessage( - PullAction.class, "MSG_PULL_FROM_NONAME", HgUtils.stripDoubleSlash(pullPath))); // NOI18N + PullAction.class, "MSG_PULL_FROM_NONAME", HgUtils.stripDoubleSlash(HgUtils.replaceHttpPassword(pullPath)))); // NOI18N } if (toPrjName != null) { HgUtils.outputMercurialTabInRed(NbBundle.getMessage( diff -r 25c88ff0be07 -r 64509e0ef84e mercurial/src/org/netbeans/modules/mercurial/ui/push/PushAction.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/push/PushAction.java Wed Feb 06 10:05:15 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/push/PushAction.java Wed Feb 06 19:17:27 2008 +0000 @@ -195,7 +195,7 @@ public class PushAction extends Abstract if (s.indexOf(Mercurial.CHANGESET_STR) == 0) { outRed.println(s); } else if (!s.equals("")) { // NOI18N - out.println(s); + out.println(HgUtils.replaceHttpPassword(s)); } } out.println(""); // NOI18N @@ -203,16 +203,16 @@ public class PushAction extends Abstract outRed.close(); } - HgUtils.outputMercurialTab(list); + HgUtils.outputMercurialTab(HgUtils.replaceHttpPassword(list)); if (toPrjName == null) { HgUtils.outputMercurialTabInRed( NbBundle.getMessage(PushAction.class, - "MSG_PUSH_TO_NONAME", bLocalPush ? HgUtils.stripDoubleSlash(pushPath) : pushPath)); // NOI18N + "MSG_PUSH_TO_NONAME", bLocalPush ? HgUtils.stripDoubleSlash(pushPath) : HgUtils.replaceHttpPassword(pushPath))); // NOI18N } else { HgUtils.outputMercurialTabInRed( NbBundle.getMessage(PushAction.class, - "MSG_PUSH_TO", toPrjName, bLocalPush ? HgUtils.stripDoubleSlash(pushPath) : pushPath)); // NOI18N + "MSG_PUSH_TO", toPrjName, bLocalPush ? HgUtils.stripDoubleSlash(pushPath) : HgUtils.replaceHttpPassword(pushPath))); // NOI18N } if (fromPrjName == null ){ diff -r 25c88ff0be07 -r 64509e0ef84e mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java --- a/mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java Wed Feb 06 10:05:15 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java Wed Feb 06 19:17:27 2008 +0000 @@ -2520,11 +2520,12 @@ public class HgCommand { } private static void handleError(List command, List list, String message) throws HgException{ - Mercurial.LOG.log(Level.WARNING, "command: " + command); // NOI18N - Mercurial.LOG.log(Level.WARNING, "output: " + list); // NOI18N - + Mercurial.LOG.log(Level.WARNING, "command: " + HgUtils.replaceHttpPassword(command)); // NOI18N + Mercurial.LOG.log(Level.WARNING, "output: " + HgUtils.replaceHttpPassword(list)); // NOI18N + HgUtils.outputMercurialTabInRed(NbBundle.getMessage(HgCommand.class, "MSG_COMMAND_ERR")); // NOI18N - HgUtils.outputMercurialTab(NbBundle.getMessage(HgCommand.class, "MSG_COMMAND_INFO_ERR", command, list)); // NOI18N + HgUtils.outputMercurialTab(NbBundle.getMessage(HgCommand.class, "MSG_COMMAND_INFO_ERR", + HgUtils.replaceHttpPassword(command), HgUtils.replaceHttpPassword(list))); // NOI18N throw new HgException(message); } diff -r 25c88ff0be07 -r 64509e0ef84e mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java --- a/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java Wed Feb 06 10:05:15 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java Wed Feb 06 19:17:27 2008 +0000 @@ -82,6 +82,7 @@ import java.util.Calendar; import java.util.Calendar; import java.util.HashMap; import java.util.logging.Level; +import java.util.regex.Matcher; import javax.swing.JOptionPane; import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileUtil; @@ -103,6 +104,9 @@ import org.openide.windows.OutputListene * @author jrice */ public class HgUtils { + private static final Pattern httpPasswordPattern = Pattern.compile("(https*://)(\\w+\\b):(\\b\\S*)@"); //NOI18N + private static final String httpPasswordReplacementStr = "$1$2:\\*\\*\\*\\*@"; //NOI18N + private static final Pattern metadataPattern = Pattern.compile(".*\\" + File.separatorChar + "(\\.)hg(\\" + File.separatorChar + ".*|$)"); // NOI18N // IGNORE SUPPORT HG: following file patterns are added to {Hg repos}/.hgignore and Hg will ignore any files @@ -125,7 +129,32 @@ public class HgUtils { public static boolean isSolaris(){ return System.getProperty("os.name").equals("SunOS"); // NOI18N } + + /** + * replaceHttpPassword - replace any http or https passwords in the string + * + * @return String modified string with **** instead of passwords + */ + public static String replaceHttpPassword(String s){ + Matcher m = httpPasswordPattern.matcher(s); + return m.replaceAll(httpPasswordReplacementStr); + } + /** + * replaceHttpPassword - replace any http or https passwords in the List + * + * @return List containing modified strings with **** instead of passwords + */ + public static List replaceHttpPassword(List list){ + if(list == null) return null; + + List out = new ArrayList(list.size()); + for(String s: list){ + out.add(replaceHttpPassword(s)); + } + return out; + } + /** * isInUserPath - check if passed in name is on the Users PATH environment setting *