# # # patch "ChangeLog" # from [dc4b2ce5e61c548e079f8ee96aa7cbd27a017876] # to [32a93921d581561e347d9706fdbecd8948c9f5f9] # # patch "constants.cc" # from [aa685613113f5ba800e3c64cc209e93072f86e7b] # to [2adbf649a11d5d2bdf7808dad6a47dd1a9e066f2] # # patch "vocab.cc" # from [9320cc58e017c5cf264819ff7cb459d066f10cc3] # to [24ee8f825c4e592cc473c51b1c135246142ce40d] # # patch "vocab.hh" # from [77bc4c6d905688d61e7d32c47ed2c777d2e67d45] # to [2bd8cac9e74aecc7e0de12a440d08fd9153bfdfa] # ============================================================ --- ChangeLog dc4b2ce5e61c548e079f8ee96aa7cbd27a017876 +++ ChangeLog 32a93921d581561e347d9706fdbecd8948c9f5f9 @@ -1,3 +1,13 @@ +2007-01-30 Nathaniel Smith + + * vocab.cc (verify(hexenc)): Rename from verify_full. Now + actually runs (!!!). + (verify_hexenc_id): New test. + * vocab.hh (is_xdigit): Disallow capitalized hex digits, above + test now passes. + * constants.cc (regex_legal_id_bytes): No capital hex digits here, + either! + 2007-01-24 Richard Levitte * debian/monotone-server.postinst, debian/changelog: update the ============================================================ --- constants.cc aa685613113f5ba800e3c64cc209e93072f86e7b +++ constants.cc 2adbf649a11d5d2bdf7808dad6a47dd1a9e066f2 @@ -85,7 +85,7 @@ namespace constants "0123456789abcdef" ; - string const regex_legal_id_bytes("([[:xdigit:]]{40})"); + string const regex_legal_id_bytes("([0-9a-f]{40})"); // all the ASCII characters (bytes) which are legal in an ACE string char const * const legal_ace_bytes = ============================================================ --- vocab.cc 9320cc58e017c5cf264819ff7cb459d066f10cc3 +++ vocab.cc 24ee8f825c4e592cc473c51b1c135246142ce40d @@ -57,8 +57,10 @@ verify_full(path_component & val) val.ok = true; } +// NOTE: _not_ verify_full; you use verify_full for ATOMICs, verify() for +// everything else. inline void -verify_full(hexenc & val) +verify(hexenc & val) { if (val().empty()) return; @@ -226,6 +228,65 @@ void dump(manifest_data const & d, strin template void dump(manifest_data const & d, string &); +#ifdef BUILD_UNIT_TESTS + +#include "unit_tests.hh" + +UNIT_TEST(vocab, verify_hexenc_id) +{ + // -------- magic empty string and default constructor are okay: + BOOST_CHECK(hexenc("")() == ""); + hexenc my_default_id; + BOOST_CHECK(my_default_id() == ""); + + // -------- wrong length: + BOOST_CHECK_THROW(hexenc("a"), informative_failure); + // 39 letters + BOOST_CHECK_THROW(hexenc("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), + informative_failure); + // 41 letters + BOOST_CHECK_THROW(hexenc("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), + informative_failure); + // but 40 is okay + BOOST_CHECK(hexenc("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")() + == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + + // -------- bad characters: + BOOST_CHECK_THROW(hexenc("g000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("h000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("G000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("H000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("*000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("`000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("z000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("Z000000000000000000000000000000000000000"), informative_failure); + // different positions: + BOOST_CHECK_THROW(hexenc("g000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("0g00000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("00g0000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("000g000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("0000g00000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("000000000000000000000g000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("0000000000000000000000g00000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("000000000000000000000000000000g000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("000000000000000000000000000000000000g000"), informative_failure); + BOOST_CHECK_THROW(hexenc("0000000000000000000000000000000000000g00"), informative_failure); + BOOST_CHECK_THROW(hexenc("00000000000000000000000000000000000000g0"), informative_failure); + BOOST_CHECK_THROW(hexenc("000000000000000000000000000000000000000g"), informative_failure); + // uppercase hex is bad too! + BOOST_CHECK_THROW(hexenc("A000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("B000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("C000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("D000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("E000000000000000000000000000000000000000"), informative_failure); + BOOST_CHECK_THROW(hexenc("F000000000000000000000000000000000000000"), informative_failure); + // but lowercase and digits are all fine + BOOST_CHECK(hexenc("0123456789abcdef0123456789abcdef01234567")() + == "0123456789abcdef0123456789abcdef01234567"); +} + +#endif // BUILD_UNIT_TESTS + // Local Variables: // mode: C++ // fill-column: 76 ============================================================ --- vocab.hh 77bc4c6d905688d61e7d32c47ed2c777d2e67d45 +++ vocab.hh 2bd8cac9e74aecc7e0de12a440d08fd9153bfdfa @@ -44,8 +44,7 @@ inline bool is_xdigit(char x) inline bool is_xdigit(char x) { return ((x >= '0' && x <= '9') - || (x >= 'a' && x <= 'f') - || (x >= 'A' && x <= 'F')); + || (x >= 'a' && x <= 'f')); } inline bool is_alpha(char x)