Skip to content

Commit a166a18

Browse files
committed
Allow valid RFC 3986 URL schemes in UrlOpener
Accept any syntactically valid scheme (such as mailto:, x-apple.systempreferences:, ms-settings:, or custom app deep links) instead of restricting to http/https.
1 parent 4037996 commit a166a18

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/url_opener.cpp‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,23 @@ UrlOpenResult ValidateUrl(const std::string& raw_url) {
4747
}
4848

4949
const std::string scheme = ToLower(url.substr(0, scheme_separator));
50-
if (scheme != "http" && scheme != "https") {
50+
auto is_valid_scheme = [](const std::string& s) {
51+
if (s.empty() || !std::isalpha(static_cast<unsigned char>(s[0]))) {
52+
return false;
53+
}
54+
for (size_t i = 1; i < s.size(); ++i) {
55+
const unsigned char ch = static_cast<unsigned char>(s[i]);
56+
if (!std::isalnum(ch) && ch != '+' && ch != '-' && ch != '.') {
57+
return false;
58+
}
59+
}
60+
return true;
61+
};
62+
if (!is_valid_scheme(scheme)) {
5163
UrlOpenResult result;
5264
result.success = false;
5365
result.error_code = UrlOpenErrorCode::kInvalidUrlUnsupportedScheme;
54-
result.error_message = "Only http and https URLs are supported.";
66+
result.error_message = "URL scheme is invalid.";
5567
return result;
5668
}
5769

0 commit comments

Comments
 (0)