summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-10-30 10:14:08 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-10-30 10:14:08 +0100
commitbeabc8d998249ecc5dd522d696dc6233a29131c2 (patch)
tree3810745cd0f57df8ae9de04ce3fc2b37d8c3bd1b /modules
parent332b65e4ccb6ac0d606de2a1b23f5189c72542be (diff)
modules: Allow absolute paths for project imports
Fixes #7910
Diffstat (limited to 'modules')
-rw-r--r--modules/client.go11
-rw-r--r--modules/client_test.go9
2 files changed, 19 insertions, 1 deletions
diff --git a/modules/client.go b/modules/client.go
index c6f43298d..7d2175c94 100644
--- a/modules/client.go
+++ b/modules/client.go
@@ -614,10 +614,19 @@ func (c *Client) shouldVendor(path string) bool {
}
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
}
diff --git a/modules/client_test.go b/modules/client_test.go
index 7354f15e8..7cc1058fc 100644
--- a/modules/client_test.go
+++ b/modules/client_test.go
@@ -15,6 +15,7 @@ package modules
import (
"bytes"
+ "fmt"
"os"
"path/filepath"
"testing"
@@ -157,6 +158,14 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
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))
+
})
}