Fix absolute and relative without parent dir paths work

master
Bel LaPointe 2019-11-21 12:28:30 -07:00
parent 9fc4e63a34
commit 3079cd163f
11 changed files with 59 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
gollum
public
**.sw*
**/**.sw*
*.sw*

View File

@ -16,7 +16,11 @@ type Path struct {
}
func NewPathFromLocal(p string) Path {
splits := strings.SplitN(p, path.Base(config.Root)+"/", 2)
root := config.Root + "/"
if strings.HasPrefix(root, "./") {
root = root[2:]
}
splits := strings.SplitN(p, root, 2)
href := splits[0]
if len(splits) > 1 && (splits[0] == "" || splits[0] == "/") {
href = splits[1]

View File

@ -32,6 +32,12 @@ func TestNewPathFromLocal(t *testing.T) {
href string
local string
}{
{
in: "/wiki/wiki/b/a.md",
root: "/wiki/wiki",
href: "/notes/b/a.md",
local: "/wiki/wiki/b/a.md",
},
{
in: "/wiki/b/a.md",
root: "/wiki",

View File

@ -16,16 +16,26 @@ import (
)
func TestAll(t *testing.T) {
makeFiles(t)
defer os.RemoveAll(config.Root)
log.Println(config.Root)
s := makeServer(t)
defer s.Close()
testServer(t, s.URL)
for _, basedir := range []string{os.TempDir(), "./tempDir"} {
os.MkdirAll(basedir, os.ModePerm)
makeFiles(t, basedir)
if basedir[0] == '.' && config.Root[0] != '.' {
config.Root = "./" + config.Root
}
defer os.RemoveAll(config.Root)
log.Println(config.Root)
t.Log("trying with root", config.Root)
s := makeServer(t)
defer s.Close()
testServer(t, s.URL)
if basedir[0] == '.' {
os.RemoveAll(basedir)
}
}
}
func makeFiles(t *testing.T) {
d, err := ioutil.TempDir(os.TempDir(), "pattern*")
func makeFiles(t *testing.T, basedir string) {
d, err := ioutil.TempDir(basedir, "pattern*")
if err != nil {
t.Fatal(err)
}

1
public/A/D/G/A/b Executable file
View File

@ -0,0 +1 @@
asdf

1
public/A/abc Executable file
View File

@ -0,0 +1 @@
asdf

1
public/A/asdf Executable file
View File

@ -0,0 +1 @@
asdf

12
public/A/x Executable file
View File

@ -0,0 +1,12 @@
# A.x
| hello | world |
|-------|-------|
| cont | ent. |
## A.X
1
2
3

5
public/B/y Executable file
View File

@ -0,0 +1,5 @@
## B.y
| hello | world |
|-------|-------|
| cont | ent. |

8
public/B/z Executable file
View File

@ -0,0 +1,8 @@
## B.z
| hello | world |
|-------|-------|
| cont | ent. |
HI

1
public/D/E/F/g Executable file
View File

@ -0,0 +1 @@
hi