Validate private use language tags
authorJoe Mooring <joe.mooring@veriphor.com>
Sun, 7 Nov 2021 15:06:48 +0000 (07:06 -0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 2 Dec 2021 15:30:53 +0000 (16:30 +0100)
Fixes #9119

hugolib/hugo_modules_test.go
langs/i18n/translationProvider.go

index ff3d01c04941c5fe24c33ba1fc514b2f94f67dcb..464230437502be0cd0478be36676bfa1fb7fa08a 100644 (file)
@@ -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)
+                       }
                }
        }
 
index 9e82b18d9c92c0b919c975cb8a0b802a530670a1..44bd52f0c369300de272acf790d4ee84878b9955 100644 (file)
@@ -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
        }