diff --git a/src/lib/src/tags/tag-name-format.cpp b/src/lib/src/tags/tag-name-format.cpp index d206df710..219dc5309 100644 --- a/src/lib/src/tags/tag-name-format.cpp +++ b/src/lib/src/tags/tag-name-format.cpp @@ -63,7 +63,7 @@ QString TagNameFormat::formatted(const QString &word, int index) const case TagNameFormat::UpperFirst: { auto res = word.toLower(); - if (index == 0 || m_caseFormat == TagNameFormat::Upper) { + if ((index == 0 || m_caseFormat == TagNameFormat::Upper) && res.length() > 0) { res[0] = res[0].toUpper(); } return res; diff --git a/src/lib/tests/src/tags/tag-name-format-test.cpp b/src/lib/tests/src/tags/tag-name-format-test.cpp index 0fb7c1449..9cc33f167 100644 --- a/src/lib/tests/src/tags/tag-name-format-test.cpp +++ b/src/lib/tests/src/tags/tag-name-format-test.cpp @@ -13,6 +13,7 @@ TEST_CASE("TagNameFormat") REQUIRE(format.formatted(QStringList() << "test") == QString("test")); REQUIRE(format.formatted(QStringList() << "test" << "tag") == QString("test_tag")); REQUIRE(format.formatted(QStringList() << "Test" << "tAG") == QString("test_tag")); + REQUIRE(format.formatted(QStringList() << "" << "Test" << "") == QString("_test_")); } SECTION("UpperFirst") @@ -23,6 +24,7 @@ TEST_CASE("TagNameFormat") REQUIRE(format.formatted(QStringList() << "test") == QString("Test")); REQUIRE(format.formatted(QStringList() << "test" << "tag") == QString("Test_tag")); REQUIRE(format.formatted(QStringList() << "Test" << "tAG") == QString("Test_tag")); + REQUIRE(format.formatted(QStringList() << "" << "Test" << "") == QString("_test_")); } SECTION("Upper") @@ -33,6 +35,7 @@ TEST_CASE("TagNameFormat") REQUIRE(format.formatted(QStringList() << "test") == QString("Test")); REQUIRE(format.formatted(QStringList() << "test" << "tag") == QString("Test_Tag")); REQUIRE(format.formatted(QStringList() << "Test" << "tAG") == QString("Test_Tag")); + REQUIRE(format.formatted(QStringList() << "" << "Test" << "") == QString("_Test_")); } SECTION("Caps") @@ -43,6 +46,7 @@ TEST_CASE("TagNameFormat") REQUIRE(format.formatted(QStringList() << "test") == QString("TEST")); REQUIRE(format.formatted(QStringList() << "test" << "tag") == QString("TEST_TAG")); REQUIRE(format.formatted(QStringList() << "Test" << "tAG") == QString("TEST_TAG")); + REQUIRE(format.formatted(QStringList() << "" << "Test" << "") == QString("_TEST_")); } SECTION("Unknown") @@ -53,5 +57,6 @@ TEST_CASE("TagNameFormat") REQUIRE(format.formatted(QStringList() << "test") == QString("test")); REQUIRE(format.formatted(QStringList() << "test" << "tag") == QString("test tag")); REQUIRE(format.formatted(QStringList() << "Test" << "tAG") == QString("Test tAG")); + REQUIRE(format.formatted(QStringList() << "" << "Test" << "") == QString(" Test ")); } }