提交 ff66e8fa 编写于 作者: J Jeffrey Wilcke

Merge pull request #1562 from ethersphere/blankpasswd

jsre: leave out lines from history possibly containing passwords
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"sort" "sort"
...@@ -44,6 +45,10 @@ import ( ...@@ -44,6 +45,10 @@ import (
"github.com/robertkrimen/otto" "github.com/robertkrimen/otto"
) )
var passwordRegexp = regexp.MustCompile("personal.[nu]")
const passwordRepl = ""
type prompter interface { type prompter interface {
AppendHistory(string) AppendHistory(string)
Prompt(p string) (string, error) Prompt(p string) (string, error)
...@@ -413,8 +418,10 @@ func (self *jsre) interactive() { ...@@ -413,8 +418,10 @@ func (self *jsre) interactive() {
str += input + "\n" str += input + "\n"
self.setIndent() self.setIndent()
if indentCount <= 0 { if indentCount <= 0 {
hist := str[:len(str)-1] hist := hidepassword(str[:len(str)-1])
self.AppendHistory(hist) if len(hist) > 0 {
self.AppendHistory(hist)
}
self.parseInput(str) self.parseInput(str)
str = "" str = ""
} }
...@@ -422,6 +429,14 @@ func (self *jsre) interactive() { ...@@ -422,6 +429,14 @@ func (self *jsre) interactive() {
} }
} }
func hidepassword(input string) string {
if passwordRegexp.MatchString(input) {
return passwordRepl
} else {
return input
}
}
func (self *jsre) withHistory(op func(*os.File)) { func (self *jsre) withHistory(op func(*os.File)) {
datadir := common.DefaultDataDir() datadir := common.DefaultDataDir()
if self.ethereum != nil { if self.ethereum != nil {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册