29 const wxScopedCharBuffer utf8 = aValue.ToUTF8();
30 const char* p = utf8.data();
31 size_t len = utf8.length();
33 for(
size_t i = 0; i < len; ++i )
35 unsigned char byte =
static_cast<unsigned char>( p[i] );
37 if( (
byte >=
'A' &&
byte <=
'Z' ) || (
byte >=
'a' &&
byte <=
'z' )
38 || (
byte >=
'0' &&
byte <=
'9' ) ||
byte ==
'-' ||
byte ==
'_'
39 ||
byte ==
'.' ||
byte ==
'~' )
41 encoded.Append(
static_cast<char>(
byte ) );
45 encoded.Append( wxString::Format( wxS(
"%%%02X" ),
byte ) );
55 auto it = aObject.find( aKey );
57 if( it != aObject.end() && it->is_string() )
58 return wxString::FromUTF8( it->get_ref<
const std::string&>().c_str() );
66 wxString host = aHost.Lower();
68 if( host.StartsWith( wxS(
"[" ) ) && host.EndsWith( wxS(
"]" ) ) )
74 return host == wxS(
"localhost" ) || host == wxS(
"127.0.0.1" ) || host == wxS(
"::1" );
79 wxString& aError,
const wxString& aLabel )
85 wxString scheme = uri.GetScheme().Lower();
87 if( scheme == wxS(
"https" ) )
90 if( scheme == wxS(
"http" ) && aAllowInsecureLocalhost &&
IsLoopbackHost( uri.GetServer() ) )
93 aError = wxString::Format(
94 _(
"%s must use HTTPS unless allow_insecure_localhost is enabled for a loopback URL." ),
107 if( !uri.HasScheme() || !uri.HasServer() )
110 wxString scheme = uri.GetScheme().Lower();
111 wxString host = uri.GetServer().Lower();
112 wxString port = uri.GetPort();
116 if( scheme == wxS(
"https" ) )
118 else if( scheme == wxS(
"http" ) )
122 return scheme + wxS(
"://" ) + host + wxS(
":" ) + port;
127 const nlohmann::json& aInstance,
128 const std::string& aMessage )
130 wxUnusedVar( aInstance );
131 m_errors.emplace_back( wxString::Format( wxS(
"%s: %s" ),
132 wxString::FromUTF8( aPointer.to_string().c_str() ),
133 wxString::FromUTF8( aMessage.c_str() ) ) );
wxString FirstError() const
void error(const nlohmann::json::json_pointer &aPointer, const nlohmann::json &aInstance, const std::string &aMessage) override
std::vector< wxString > m_errors
wxString NormalizedUrlOrigin(const wxString &aUrl)
Return a normalized scheme://host:port origin string for aUrl.
wxString UrlEncode(const wxString &aValue)
Percent-encode a string for use in URL query parameters (RFC 3986 unreserved characters are passed th...
wxString RemoteProviderJsonString(const nlohmann::json &aObject, const char *aKey)
Extract an optional string value from a JSON object, returning an empty wxString when the key is abse...
bool IsLoopbackHost(const wxString &aHost)
Return true when aHost resolves to a loopback address (localhost, 127.0.0.1, or ::1).
bool ValidateRemoteUrlSecurity(const wxString &aUrl, bool aAllowInsecureLocalhost, wxString &aError, const wxString &aLabel)
Validate that aUrl uses HTTPS, or HTTP on a loopback address when aAllowInsecureLocalhost is true.