}
func (c *Client) createThemeDirname(modulePath string, isProjectMod bool) (string, error) {
+ invalid := errors.Errorf("invalid module path %q; must be relative to themesDir when defined outside of the project", modulePath)
+
modulePath = filepath.Clean(modulePath)
+ if filepath.IsAbs(modulePath) {
+ if isProjectMod {
+ return modulePath, nil
+ }
+ return "", invalid
+ }
+
moduleDir := filepath.Join(c.ccfg.ThemesDir, modulePath)
if !isProjectMod && !strings.HasPrefix(moduleDir, c.ccfg.ThemesDir) {
- return "", errors.Errorf("invalid module path %q; must be relative to themesDir when defined outside of the project", modulePath)
+ return "", invalid
}
return moduleDir, nil
}
import (
"bytes"
+ "fmt"
"os"
"path/filepath"
"testing"
dirname, err = client.createThemeDirname("../../foo", false)
c.Assert(err, qt.Not(qt.IsNil))
+ absDir := filepath.Join(client.ccfg.WorkingDir, "..", "..")
+ dirname, err = client.createThemeDirname(absDir, true)
+ c.Assert(err, qt.IsNil)
+ c.Assert(dirname, qt.Equals, absDir)
+ dirname, err = client.createThemeDirname(absDir, false)
+ fmt.Println(dirname)
+ c.Assert(err, qt.Not(qt.IsNil))
+
})
}