mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-14 10:29:35 +00:00
match a wildcard only in the leftmost label in match_hostname (#2619)
* match a wildcard only in the leftmost label in match_hostname * Shorten the wildcard comment in match_hostname --------- Co-authored-by: yhirose <yuji.hirose.bug@gmail.com>
This commit is contained in:
1 parent
00afaaed6a
commit
8f094fe292
5 files changed
+86
-3
No files matched your search
@@ -10759,12 +10759,14 @@ inline bool match_hostname(const std::string &pattern,
|
||||
// Compare each component with wildcard support
|
||||
// Supports: "*" (full wildcard), "prefix*" (partial wildcard)
|
||||
// https://bugs.launchpad.net/ubuntu/+source/firefox-3.0/+bug/376484
|
||||
// Only the leftmost label may carry a wildcard (RFC 6125 6.4.3)
|
||||
auto itr = pattern_components.begin();
|
||||
for (const auto &h : host_components) {
|
||||
auto &p = *itr;
|
||||
if (!detail::case_ignore::equal(p, h) && p != "*") {
|
||||
auto is_leftmost = itr == pattern_components.begin();
|
||||
if (!detail::case_ignore::equal(p, h) && !(is_leftmost && p == "*")) {
|
||||
bool partial_match = false;
|
||||
if (!p.empty() && p[p.size() - 1] == '*') {
|
||||
if (is_leftmost && !p.empty() && p[p.size() - 1] == '*') {
|
||||
const auto prefix_length = p.size() - 1;
|
||||
if (prefix_length == 0) {
|
||||
partial_match = true;
|
||||
|
||||
Reference in new issue
Block a user