Skip to content

Commit

Permalink
Validate private use language tags
Browse files Browse the repository at this point in the history
Fixes #9119
  • Loading branch information
jmooring authored and bep committed Dec 2, 2021
1 parent 93572e5 commit 58adbee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions hugolib/hugo_modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,13 @@ Data: {{ .Site.Data }}

createSymlinks := func(baseDir, id string) {
for _, dir := range files.ComponentFolders {
c.Assert(os.Chdir(filepath.Join(baseDir, dir)), qt.IsNil)
c.Assert(os.Symlink("real", fmt.Sprintf("realsym%s", id)), qt.IsNil)
c.Assert(os.Chdir(filepath.Join(baseDir, dir, "real")), qt.IsNil)
c.Assert(os.Symlink("data.toml", fmt.Sprintf(filepath.FromSlash("datasym%s.toml"), id)), qt.IsNil)
// Issue #9119: private use language tags cannot exceed 8 characters.
if dir != "i18n" {
c.Assert(os.Chdir(filepath.Join(baseDir, dir)), qt.IsNil)
c.Assert(os.Symlink("real", fmt.Sprintf("realsym%s", id)), qt.IsNil)
c.Assert(os.Chdir(filepath.Join(baseDir, dir, "real")), qt.IsNil)
c.Assert(os.Symlink("data.toml", fmt.Sprintf(filepath.FromSlash("datasym%s.toml"), id)), qt.IsNil)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions langs/i18n/translationProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func addTranslationFile(bundle *i18n.Bundle, r source.File) error {
lang := paths.Filename(name)
tag := language.Make(lang)
if tag == language.Und {
try := artificialLangTagPrefix + lang
_, err = language.Parse(try)
if err != nil {
return _errors.Errorf("%q %s.", try, err)
}
name = artificialLangTagPrefix + name
}

Expand Down

0 comments on commit 58adbee

Please sign in to comment.