diff --git a/NEWS.md b/NEWS.md index a28a9913a..200941355 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,10 @@ * MKVToolNix GUI: IETF BCP 47 language tags: the "variants" combo-boxes were not populated even when the language tag was valid and contained at a variant. Fixes #2923. +* MKVToolNix GUI: IETF BCP 47 language tags: when no language is selected, at + least one of the other components (extended subtags, region, or variants) + has something selected and "private use" is not empty, the GUI would claim + this to be a valid tag, which it isn't. Fixes #2924. # Version 50.0.0 "Awakenings" 2020-09-06 diff --git a/src/common/bcp47.cpp b/src/common/bcp47.cpp index ee94715cc..ae667650c 100644 --- a/src/common/bcp47.cpp +++ b/src/common/bcp47.cpp @@ -79,15 +79,6 @@ language_c::format_internal(bool force) if (!m_valid && !force) return {}; - if (m_language.empty()) { - auto output = "x"s; - - for (auto const &private_use : m_private_use) - output += fmt::format("-{}", mtx::string::to_lower_ascii(private_use)); - - return output; - } - auto output = mtx::string::to_lower_ascii(m_language); for (auto const &subtag : m_extended_language_subtags) @@ -106,7 +97,11 @@ language_c::format_internal(bool force) output += fmt::format("-{}", mtx::string::to_lower_ascii(extension)); if (!m_private_use.empty()) { - output += "-x"; + if (!output.empty()) + output += "-"; + + output += "x"; + for (auto const &private_use : m_private_use) output += fmt::format("-{}", mtx::string::to_lower_ascii(private_use)); } diff --git a/tests/unit/common/bcp47.cpp b/tests/unit/common/bcp47.cpp index bb341fbe6..d213f1408 100644 --- a/tests/unit/common/bcp47.cpp +++ b/tests/unit/common/bcp47.cpp @@ -79,6 +79,16 @@ TEST(BCP47LanguageTags, Formatting) { EXPECT_EQ("x-weee-wooo"s, l.format_long(true)); } +TEST(BCP47LanguageTags, FormattingInvalidWithoutLanguage) { + auto l = mtx::bcp47::language_c{}; + + l.set_region("FR"s); + l.set_private_use({ "moo"s }); + + EXPECT_EQ(""s, l.format()); + EXPECT_EQ("-FR-x-moo"s, l.format(true)); +} + TEST(BCP47LanguageTags, CodeConversion) { EXPECT_EQ(""s, mtx::bcp47::language_c{}.get_iso639_2_code()); EXPECT_EQ("ger"s, mtx::bcp47::language_c::parse("de").get_iso639_2_code());