aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/mail.go
diff options
context:
space:
mode:
authorYury Smolsky <yury@smolsky.by>2018-03-21 01:23:00 +0200
committerBrad Fitzpatrick <bradfitz@golang.org>2018-03-30 21:38:54 +0000
commitfebe82b3542e335479ef0e8a401a0e95f070fa41 (patch)
treeb3d746400bde7ae847f6c7e8d00ca929c6ba06c5 /git-codereview/mail.go
parent34696713d8ce9c6e709a50d8192fd973246a30e9 (diff)
downloadgo-x-review-febe82b3542e335479ef0e8a401a0e95f070fa41.tar.xz
git-codereview: forbid mailing editor temp files
"mail" command rejects *~, #*# and .#* filenames. Also it should reject commit messages with non-printable characters, because these are impossible to spot in the review. For golang/go#24139 Change-Id: I3544e3c34c5ac9f55a7808264de4535bc455bd0a Reviewed-on: https://go-review.googlesource.com/101755 Run-TryBot: Yury Smolsky <yury@smolsky.by> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'git-codereview/mail.go')
-rw-r--r--git-codereview/mail.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/git-codereview/mail.go b/git-codereview/mail.go
index a63790f..3bea462 100644
--- a/git-codereview/mail.go
+++ b/git-codereview/mail.go
@@ -10,6 +10,8 @@ import (
"regexp"
"sort"
"strings"
+ "unicode"
+ "unicode/utf8"
)
func cmdMail(args []string) {
@@ -68,6 +70,13 @@ func cmdMail(args []string) {
if strings.HasPrefix(c1.Message, "squash!") {
dief("%s: CL is a squash! commit", c1.ShortHash)
}
+
+ for _, f := range ListFiles(c1) {
+ if strings.HasPrefix(f, ".#") || strings.HasSuffix(f, "~") ||
+ (strings.HasPrefix(f, "#") && strings.HasSuffix(f, "#")) {
+ dief("cannot mail temporary files: %s", f)
+ }
+ }
}
if !foundCommit {
// b.CommitByRev and b.DefaultCommit both return a commit on b.
@@ -79,6 +88,15 @@ func cmdMail(args []string) {
"Use '%s change' to include them or '%s mail -f' to force it.", os.Args[0], os.Args[0])
}
+ if !utf8.ValidString(c.Message) {
+ dief("cannot mail message with invalid UTF-8")
+ }
+ for _, r := range c.Message {
+ if !unicode.IsPrint(r) && !unicode.IsSpace(r) {
+ dief("cannot mail message with non-printable rune %q", r)
+ }
+ }
+
// for side effect of dying with a good message if origin is GitHub
loadGerritOrigin()