mirror of
https://github.com/golang/go
synced 2024-11-24 20:20:03 -07:00
filepath/path: fix Rel buffer sizing
Fixes #2493. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5433079
This commit is contained in:
parent
f1fecf8d2a
commit
a620865639
@ -312,7 +312,11 @@ func Rel(basepath, targpath string) (string, error) {
|
|||||||
if b0 != bl {
|
if b0 != bl {
|
||||||
// Base elements left. Must go up before going down.
|
// Base elements left. Must go up before going down.
|
||||||
seps := strings.Count(base[b0:bl], string(Separator))
|
seps := strings.Count(base[b0:bl], string(Separator))
|
||||||
buf := make([]byte, 3+seps*3+tl-t0)
|
size := 2 + seps*3
|
||||||
|
if tl != t0 {
|
||||||
|
size += 1 + tl - t0
|
||||||
|
}
|
||||||
|
buf := make([]byte, size)
|
||||||
n := copy(buf, "..")
|
n := copy(buf, "..")
|
||||||
for i := 0; i < seps; i++ {
|
for i := 0; i < seps; i++ {
|
||||||
buf[n] = Separator
|
buf[n] = Separator
|
||||||
|
@ -629,6 +629,10 @@ var reltests = []RelTests{
|
|||||||
{"a/b/../c", "a/b", "../b"},
|
{"a/b/../c", "a/b", "../b"},
|
||||||
{"a/b/c", "a/c/d", "../../c/d"},
|
{"a/b/c", "a/c/d", "../../c/d"},
|
||||||
{"a/b", "c/d", "../../c/d"},
|
{"a/b", "c/d", "../../c/d"},
|
||||||
|
{"a/b/c/d", "a/b", "../.."},
|
||||||
|
{"a/b/c/d", "a/b/", "../.."},
|
||||||
|
{"a/b/c/d/", "a/b", "../.."},
|
||||||
|
{"a/b/c/d/", "a/b/", "../.."},
|
||||||
{"../../a/b", "../../a/b/c/d", "c/d"},
|
{"../../a/b", "../../a/b/c/d", "c/d"},
|
||||||
{"/a/b", "/a/b", "."},
|
{"/a/b", "/a/b", "."},
|
||||||
{"/a/b/.", "/a/b", "."},
|
{"/a/b/.", "/a/b", "."},
|
||||||
@ -640,6 +644,10 @@ var reltests = []RelTests{
|
|||||||
{"/a/b/../c", "/a/b", "../b"},
|
{"/a/b/../c", "/a/b", "../b"},
|
||||||
{"/a/b/c", "/a/c/d", "../../c/d"},
|
{"/a/b/c", "/a/c/d", "../../c/d"},
|
||||||
{"/a/b", "/c/d", "../../c/d"},
|
{"/a/b", "/c/d", "../../c/d"},
|
||||||
|
{"/a/b/c/d", "/a/b", "../.."},
|
||||||
|
{"/a/b/c/d", "/a/b/", "../.."},
|
||||||
|
{"/a/b/c/d/", "/a/b", "../.."},
|
||||||
|
{"/a/b/c/d/", "/a/b/", "../.."},
|
||||||
{"/../../a/b", "/../../a/b/c/d", "c/d"},
|
{"/../../a/b", "/../../a/b/c/d", "c/d"},
|
||||||
{".", "a/b", "a/b"},
|
{".", "a/b", "a/b"},
|
||||||
{".", "..", ".."},
|
{".", "..", ".."},
|
||||||
|
Loading…
Reference in New Issue
Block a user