Commit 2b4a9603 authored by Russ Cox's avatar Russ Cox

io/ioutil: use filepath.Join, handle trailing / in $TMPDIR

R=niemeyer
CC=golang-dev
https://golang.org/cl/4256057
parent 94401f52
...@@ -7,6 +7,7 @@ package ioutil_test ...@@ -7,6 +7,7 @@ package ioutil_test
import ( import (
. "io/ioutil" . "io/ioutil"
"os" "os"
"path/filepath"
"regexp" "regexp"
"testing" "testing"
) )
...@@ -25,7 +26,7 @@ func TestTempFile(t *testing.T) { ...@@ -25,7 +26,7 @@ func TestTempFile(t *testing.T) {
if f != nil { if f != nil {
f.Close() f.Close()
os.Remove(f.Name()) os.Remove(f.Name())
re := regexp.MustCompile("^" + regexp.QuoteMeta(dir) + "/ioutil_test[0-9]+$") re := regexp.MustCompile("^" + regexp.QuoteMeta(filepath.Join(dir, "ioutil_test")) + "[0-9]+$")
if !re.MatchString(f.Name()) { if !re.MatchString(f.Name()) {
t.Errorf("TempFile(`"+dir+"`, `ioutil_test`) created bad name %s", f.Name()) t.Errorf("TempFile(`"+dir+"`, `ioutil_test`) created bad name %s", f.Name())
} }
...@@ -45,7 +46,7 @@ func TestTempDir(t *testing.T) { ...@@ -45,7 +46,7 @@ func TestTempDir(t *testing.T) {
} }
if name != "" { if name != "" {
os.Remove(name) os.Remove(name)
re := regexp.MustCompile("^" + regexp.QuoteMeta(dir) + "/ioutil_test[0-9]+$") re := regexp.MustCompile("^" + regexp.QuoteMeta(filepath.Join(dir, "ioutil_test")) + "[0-9]+$")
if !re.MatchString(name) { if !re.MatchString(name) {
t.Errorf("TempDir(`"+dir+"`, `ioutil_test`) created bad name %s", name) t.Errorf("TempDir(`"+dir+"`, `ioutil_test`) created bad name %s", name)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment