src: Don't allow const char * in ends_with and ends_with_l
This commit is contained in:
parent
2ab79f4938
commit
841b3c87db
|
@ -735,7 +735,7 @@ bool check_path(const std::string &path) {
|
|||
path.find('\\') == std::string::npos &&
|
||||
path.find("/../") == std::string::npos &&
|
||||
path.find("/./") == std::string::npos &&
|
||||
!util::ends_with(path, "/..") && !util::ends_with(path, "/.");
|
||||
!util::ends_with_l(path, "/..") && !util::ends_with_l(path, "/.");
|
||||
}
|
||||
|
||||
int64_t to_time64(const timeval &tv) {
|
||||
|
|
10
src/util.h
10
src/util.h
|
@ -242,13 +242,13 @@ bool ends_with(InputIterator1 first1, InputIterator1 last1,
|
|||
return std::equal(first2, last2, last1 - (last2 - first2));
|
||||
}
|
||||
|
||||
inline bool ends_with(const std::string &a, const std::string &b) {
|
||||
return ends_with(std::begin(a), std::end(a), std::begin(b), std::end(b));
|
||||
template <typename T, typename S> bool ends_with(const T &a, const S &b) {
|
||||
return ends_with(a.begin(), a.end(), b.begin(), b.end());
|
||||
}
|
||||
|
||||
template <typename CharT, size_t N>
|
||||
bool ends_with_l(const StringRef &a, const CharT(&b)[N]) {
|
||||
return ends_with(std::begin(a), std::end(a), b, b + N - 1);
|
||||
template <typename T, typename CharT, size_t N>
|
||||
bool ends_with_l(const T &a, const CharT(&b)[N]) {
|
||||
return ends_with(a.begin(), a.end(), b, b + N - 1);
|
||||
}
|
||||
|
||||
template <typename InputIterator1, typename InputIterator2>
|
||||
|
|
|
@ -394,10 +394,13 @@ void test_util_starts_with(void) {
|
|||
}
|
||||
|
||||
void test_util_ends_with(void) {
|
||||
CU_ASSERT(util::ends_with("foo", "foo"));
|
||||
CU_ASSERT(util::ends_with("foo", ""));
|
||||
CU_ASSERT(util::ends_with("ofoo", "foo"));
|
||||
CU_ASSERT(!util::ends_with("ofoo", "fo"));
|
||||
CU_ASSERT(
|
||||
util::ends_with(StringRef::from_lit("foo"), StringRef::from_lit("foo")));
|
||||
CU_ASSERT(util::ends_with(StringRef::from_lit("foo"), StringRef{}));
|
||||
CU_ASSERT(
|
||||
util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("foo")));
|
||||
CU_ASSERT(
|
||||
!util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo")));
|
||||
|
||||
CU_ASSERT(
|
||||
util::iends_with(StringRef::from_lit("fOo"), StringRef::from_lit("Foo")));
|
||||
|
|
Loading…
Reference in New Issue