aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-05-02 17:55:19 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-05-02 17:55:19 +0000
commit213d79e1a635f92799f5c3ca19efdd1bb0c3ad7f (patch)
tree5d114627dd9467edfab83078bb47588cdb247b56
parentb426a95e708a128f592142e44facab2eeb9c3d9e (diff)
downloadpaludis-213d79e1a635f92799f5c3ca19efdd1bb0c3ad7f.tar.gz
paludis-213d79e1a635f92799f5c3ca19efdd1bb0c3ad7f.tar.xz
Small improvements and PMS compliance changes in name validators. Fixes: ticket:159 ticket:160
-rw-r--r--paludis/name.cc27
-rw-r--r--paludis/name_TEST.cc145
2 files changed, 161 insertions, 11 deletions
diff --git a/paludis/name.cc b/paludis/name.cc
index c6b3f3c..280c9fb 100644
--- a/paludis/name.cc
+++ b/paludis/name.cc
@@ -51,14 +51,19 @@ UseFlagNameValidator::validate(const std::string & s)
static const std::string allowed_chars(
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789-+_:@");
+ "0123456789-+_@");
+
+ static const std::string alphanum_chars(
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789");
do
{
if (s.empty())
break;
- if ('-' == s.at(0) || '.' == s[0])
+ if (std::string::npos == alphanum_chars.find(s[0]))
break;
if (std::string::npos != s.find_first_not_of(allowed_chars))
@@ -96,7 +101,7 @@ SlotNameValidator::validate(const std::string & s)
if (s.empty())
break;
- if ('-' == s.at(0) || '.' == s[0])
+ if ('-' == s[0] || '.' == s[0])
break;
if (std::string::npos != s.find_first_not_of(allowed_chars))
@@ -129,7 +134,7 @@ PackageNamePartValidator::validate(const std::string & s)
static const std::string number_chars(
"0123456789");
- if (s.empty() || '-' == s.at(0) || '.' == s[0])
+ if (s.empty() || '-' == s[0])
{
Context c("When validating package name part '" + s + "':");
throw PackageNamePartError(s);
@@ -167,7 +172,7 @@ CategoryNamePartValidator::validate(const std::string & s)
if (s.empty())
break;
- if ('-' == s.at(0) || '.' == s[0])
+ if ('-' == s[0] || '.' == s[0])
break;
if (std::string::npos != s.find_first_not_of(allowed_chars))
@@ -192,14 +197,14 @@ RepositoryNameValidator::validate(const std::string & s)
static const std::string allowed_chars(
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789-+_");
+ "0123456789-_");
do
{
if (s.empty())
break;
- if ('-' == s.at(0) || '.' == s[0])
+ if ('-' == s[0])
break;
if (std::string::npos != s.find_first_not_of(allowed_chars))
@@ -229,7 +234,7 @@ KeywordNameValidator::validate(const std::string & s)
static const std::string allowed_chars(
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789-+_");
+ "0123456789-_");
do
{
@@ -247,10 +252,10 @@ KeywordNameValidator::validate(const std::string & s)
if ("-*" == s)
return;
- /* fall throuth */
+ /* fall through */
default:
if (std::string::npos != s.find_first_not_of(allowed_chars,
- ('~' == s.at(0) ? 1 : 0)))
+ ('~' == s[0] ? 1 : 0)))
continue;
}
@@ -310,7 +315,7 @@ SetNameValidator::validate(const std::string & s)
if (s.empty())
break;
- if ('-' == s.at(0) || '.' == s[0])
+ if ('-' == s[0] || '.' == s[0])
break;
if (std::string::npos != s.find_first_not_of(allowed_chars))
diff --git a/paludis/name_TEST.cc b/paludis/name_TEST.cc
index c988ceb..60d74e1 100644
--- a/paludis/name_TEST.cc
+++ b/paludis/name_TEST.cc
@@ -196,5 +196,150 @@ namespace test_cases
}
} test_package_name_part_comparison;
+ /**
+ * \test Test RepositoryName creation.
+ *
+ */
+ struct RepositoryNameCreationTest : public TestCase
+ {
+ RepositoryNameCreationTest() : TestCase("creation") { }
+
+ void run()
+ {
+ RepositoryName r("foo");
+ TEST_CHECK(true);
+ }
+ } test_repository_name_creation;
+
+ /**
+ * \test Test RepositoryName validation.
+ *
+ */
+ struct RepositoryNameValidationTest : public TestCase
+ {
+ RepositoryNameValidationTest() : TestCase("validation") { }
+
+ void run()
+ {
+ RepositoryName r("repo0_-");
+ TEST_CHECK_THROWS(r = RepositoryName(""), NameError);
+ TEST_CHECK_THROWS(r = RepositoryName("!!!"), NameError);
+ TEST_CHECK_THROWS(r = RepositoryName("-foo"), NameError);
+ TEST_CHECK_THROWS(r = RepositoryName("fo$o"), NameError);
+ }
+ } test_repository_name_validation;
+
+ /**
+ * \test Test SlotName creation.
+ *
+ */
+ struct SlotNameCreationTest : public TestCase
+ {
+ SlotNameCreationTest() : TestCase("creation") { }
+
+ void run()
+ {
+ SlotName s("foo");
+ TEST_CHECK(true);
+ }
+ } test_slot_name_creation;
+
+ /**
+ * \test Test SlotName validation.
+ *
+ */
+ struct SlotNameValidationTest : public TestCase
+ {
+ SlotNameValidationTest() : TestCase("validation") { }
+
+ void run()
+ {
+ SlotName s("slot0+_.-");
+ TEST_CHECK_THROWS(s = SlotName(""), NameError);
+ TEST_CHECK_THROWS(s = SlotName("!!!"), NameError);
+ TEST_CHECK_THROWS(s = SlotName("-foo"), NameError);
+ TEST_CHECK_THROWS(s = SlotName(".foo"), NameError);
+ TEST_CHECK_THROWS(s = SlotName("fo$o"), NameError);
+ }
+ } test_slot_name_validation;
+
+ /**
+ * \test Test UseFlagName creation.
+ *
+ */
+ struct UseFlagNameCreationTest : public TestCase
+ {
+ UseFlagNameCreationTest() : TestCase("creation") { }
+
+ void run()
+ {
+ UseFlagName u("foo");
+ TEST_CHECK(true);
+ }
+ } test_use_flag_name_creation;
+
+ /**
+ * \test Test UseFlagName validation.
+ *
+ */
+ struct UseFlagNameValidationTest : public TestCase
+ {
+ UseFlagNameValidationTest() : TestCase("validation") { }
+
+ void run()
+ {
+ UseFlagName u("use0+_@-");
+ TEST_CHECK_THROWS(u = UseFlagName(""), NameError);
+ TEST_CHECK_THROWS(u = UseFlagName("!!!"), NameError);
+ TEST_CHECK_THROWS(u = UseFlagName("-foo"), NameError);
+ TEST_CHECK_THROWS(u = UseFlagName("_foo"), NameError);
+ TEST_CHECK_THROWS(u = UseFlagName("@foo"), NameError);
+ TEST_CHECK_THROWS(u = UseFlagName("+foo"), NameError);
+ TEST_CHECK_THROWS(u = UseFlagName("fo$o"), NameError);
+ }
+ } test_use_flag_name_validation;
+
+ /**
+ * \test Test KeywordName creation.
+ *
+ */
+ struct KeywordNameCreationTest : public TestCase
+ {
+ KeywordNameCreationTest() : TestCase("creation") { }
+
+ void run()
+ {
+ KeywordName k("foo");
+ TEST_CHECK(true);
+ }
+ } test_keyword_name_creation;
+
+ /**
+ * \test Test KeywordName validation.
+ *
+ */
+ struct KeywordNameValidationTest : public TestCase
+ {
+ KeywordNameValidationTest() : TestCase("validation") { }
+
+ void run()
+ {
+ KeywordName k("keyword0_-");
+ KeywordName k1("~keyword0_-");
+ KeywordName k2("-keyword0_-");
+ KeywordName k3("*");
+ KeywordName k4("-*");
+ TEST_CHECK_THROWS(k = KeywordName(""), NameError);
+ TEST_CHECK_THROWS(k = KeywordName("!!!"), NameError);
+ TEST_CHECK_THROWS(k = KeywordName("~"), NameError);
+ TEST_CHECK_THROWS(k = KeywordName("-"), NameError);
+ TEST_CHECK_THROWS(k = KeywordName("@foo"), NameError);
+ TEST_CHECK_THROWS(k = KeywordName("fo$o"), NameError);
+ TEST_CHECK_THROWS(k = KeywordName("foo+"), NameError);
+ }
+ } test_keyword_name_validation;
+
+
+
}