mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
Fix handling of content files with "." in them
As in, more dots than just to separate the extension and any language indicator. Fixes #4559
This commit is contained in:
@@ -292,10 +292,9 @@ func (fs *LanguageFs) newLanguageFileInfo(filename string, fi os.FileInfo) (*Lan
|
||||
|
||||
if fs.languages[fileLang] {
|
||||
lang = fileLang
|
||||
baseNameNoExt = strings.TrimSuffix(baseNameNoExt, fileLangExt)
|
||||
}
|
||||
|
||||
baseNameNoExt = strings.TrimSuffix(baseNameNoExt, fileLangExt)
|
||||
|
||||
// This connects the filename to the filesystem, not the language.
|
||||
virtualName = baseNameNoExt + "." + lang + ext
|
||||
|
||||
|
@@ -52,3 +52,47 @@ func TestLanguagFs(t *testing.T) {
|
||||
assert.Equal("page.md", lfi.RealName())
|
||||
|
||||
}
|
||||
|
||||
// Issue 4559
|
||||
func TestFilenamesHandling(t *testing.T) {
|
||||
languages := map[string]bool{
|
||||
"sv": true,
|
||||
}
|
||||
base := filepath.FromSlash("/my/base")
|
||||
assert := require.New(t)
|
||||
m := afero.NewMemMapFs()
|
||||
bfs := afero.NewBasePathFs(m, base)
|
||||
lfs := NewLanguageFs("sv", languages, bfs)
|
||||
assert.NotNil(lfs)
|
||||
assert.Equal("sv", lfs.Lang())
|
||||
|
||||
for _, test := range []struct {
|
||||
filename string
|
||||
check func(fi *LanguageFileInfo)
|
||||
}{
|
||||
{"tc-lib-color/class-Com.Tecnick.Color.Css", func(fi *LanguageFileInfo) {
|
||||
assert.Equal("class-Com.Tecnick.Color", fi.TranslationBaseName())
|
||||
assert.Equal(filepath.FromSlash("/my/base"), fi.BaseDir())
|
||||
assert.Equal(filepath.FromSlash("tc-lib-color/class-Com.Tecnick.Color.Css"), fi.Path())
|
||||
assert.Equal("class-Com.Tecnick.Color.Css", fi.RealName())
|
||||
assert.Equal(filepath.FromSlash("/my/base/tc-lib-color/class-Com.Tecnick.Color.Css"), fi.Filename())
|
||||
}},
|
||||
{"tc-lib-color/class-Com.Tecnick.Color.sv.Css", func(fi *LanguageFileInfo) {
|
||||
assert.Equal("class-Com.Tecnick.Color", fi.TranslationBaseName())
|
||||
assert.Equal("class-Com.Tecnick.Color.sv.Css", fi.RealName())
|
||||
assert.Equal(filepath.FromSlash("/my/base/tc-lib-color/class-Com.Tecnick.Color.sv.Css"), fi.Filename())
|
||||
}},
|
||||
} {
|
||||
err := afero.WriteFile(lfs, filepath.FromSlash(test.filename), []byte("abc"), 0777)
|
||||
assert.NoError(err)
|
||||
fi, err := lfs.Stat(filepath.FromSlash(test.filename))
|
||||
assert.NoError(err)
|
||||
|
||||
lfi, ok := fi.(*LanguageFileInfo)
|
||||
assert.True(ok)
|
||||
assert.Equal("sv", lfi.Lang())
|
||||
test.check(lfi)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user