mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
b33bfd40be
commit
39df7724ad
2 changed files with 34 additions and 0 deletions
|
@ -18,9 +18,11 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/hugo/hugofs"
|
"github.com/spf13/hugo/hugofs"
|
||||||
|
"golang.org/x/text/unicode/norm"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
@ -66,6 +68,11 @@ func (f *Filesystem) Files() []*File {
|
||||||
func (f *Filesystem) add(name string, reader io.Reader) (err error) {
|
func (f *Filesystem) add(name string, reader io.Reader) (err error) {
|
||||||
var file *File
|
var file *File
|
||||||
|
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
// When a file system is HFS+, its filepath is in NFD form.
|
||||||
|
name = norm.NFC.String(name)
|
||||||
|
}
|
||||||
|
|
||||||
file, err = NewFileFromAbs(f.Base, name, reader)
|
file, err = NewFileFromAbs(f.Base, name, reader)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -16,6 +16,8 @@ package source
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -82,3 +84,28 @@ func TestAddFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnicodeNorm(t *testing.T) {
|
||||||
|
if runtime.GOOS != "darwin" {
|
||||||
|
// Normalization code is only for Mac OS, since it is not necessary for other OSes.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
paths := []struct {
|
||||||
|
NFC string
|
||||||
|
NFD string
|
||||||
|
}{
|
||||||
|
{NFC: "å", NFD: "\x61\xcc\x8a"},
|
||||||
|
{NFC: "é", NFD: "\x65\xcc\x81"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range paths {
|
||||||
|
src := new(Filesystem)
|
||||||
|
_ = src.add(path.NFD, strings.NewReader(""))
|
||||||
|
f := src.Files()[0]
|
||||||
|
if f.BaseFileName() != path.NFC {
|
||||||
|
t.Fatalf("file name in NFD form should be normalized (%s)", path.NFC)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue