Skip to content

Commit

Permalink
fix: stop crashing on re-formatting tags starting with a space
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Jan 20, 2024
1 parent ee53ebb commit 007d861
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/src/tags/tag-name-format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/tests/src/tags/tag-name-format-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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 "));
}
}

0 comments on commit 007d861

Please # to comment.