util/UriUtil: uri_get_suffix() fails if name begins with dot

A file called ".jpg" is not a JPEG file with an empty name; it is
merely a hidden file.
This commit is contained in:
Max Kellermann 2013-12-29 17:30:24 +01:00
parent d7f80eab68
commit afc70c120e
2 changed files with 6 additions and 1 deletions

View File

@ -32,7 +32,8 @@ const char *
uri_get_suffix(const char *uri) uri_get_suffix(const char *uri)
{ {
const char *suffix = strrchr(uri, '.'); const char *suffix = strrchr(uri, '.');
if (suffix == nullptr) if (suffix == nullptr || suffix == uri ||
suffix[-1] == '/' || suffix[-1] == '\\')
return nullptr; return nullptr;
++suffix; ++suffix;

View File

@ -29,6 +29,10 @@ public:
"jpg")); "jpg"));
CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo.png/bar.jpg"), CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo.png/bar.jpg"),
"jpg")); "jpg"));
CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
uri_get_suffix(".jpg"));
CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
uri_get_suffix("/foo/.jpg"));
} }
void TestRemoveAuth() { void TestRemoveAuth() {