case-insensitive URI scheme comparison

Required according to RFC 3986:

> An implementation should accept uppercase letters as equivalent to
> lowercase in scheme names

Closes #330
This commit is contained in:
Max Kellermann
2018-08-02 10:38:20 +02:00
parent 116edf5fce
commit 906972973e
17 changed files with 45 additions and 43 deletions

View File

@@ -33,6 +33,7 @@
#include "event/DeferredMonitor.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "util/ASCII.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringCompare.hxx"
#include "util/StringFormat.hxx"
@@ -590,8 +591,8 @@ CurlStorage::OpenDirectory(const char *uri_utf8)
static Storage *
CreateCurlStorageURI(EventLoop &event_loop, const char *uri)
{
if (strncmp(uri, "http://", 7) != 0 &&
strncmp(uri, "https://", 8) != 0)
if (!StringStartsWithCaseASCII(uri, "http://") &&
!StringStartsWithCaseASCII(uri, "https://"))
return nullptr;
return new CurlStorage(event_loop, uri);

View File

@@ -35,6 +35,7 @@
#include "event/Call.hxx"
#include "event/DeferredMonitor.hxx"
#include "event/TimeoutMonitor.hxx"
#include "util/ASCII.hxx"
#include "util/StringCompare.hxx"
extern "C" {
@@ -401,11 +402,10 @@ NfsStorage::OpenDirectory(const char *uri_utf8)
static Storage *
CreateNfsStorageURI(EventLoop &event_loop, const char *base)
{
if (strncmp(base, "nfs://", 6) != 0)
const char *p = StringAfterPrefixCaseASCII(base, "nfs://");
if (p == nullptr)
return nullptr;
const char *p = base + 6;
const char *mount = strchr(p, '/');
if (mount == nullptr)
throw std::runtime_error("Malformed nfs:// URI");

View File

@@ -27,6 +27,7 @@
#include "fs/Traits.hxx"
#include "thread/Mutex.hxx"
#include "system/Error.hxx"
#include "util/ASCII.hxx"
#include "util/StringCompare.hxx"
#include "util/ScopeExit.hxx"
@@ -182,7 +183,7 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow)
static Storage *
CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base)
{
if (strncmp(base, "smb://", 6) != 0)
if (!StringStartsWithCaseASCII(base, "smb://"))
return nullptr;
SmbclientInit();