Regex support #1

Merged
Sophia merged 6 commits from Maingron/better-yourls-blacklist-domains:master into master 2025-09-12 22:36:09 -07:00
Showing only changes of commit bd050d27c4 - Show all commits

View File

@@ -45,10 +45,17 @@ function better_blacklist_domain_check( $shunt, $url ) {
$blacklisted_domains = unserialize( $blacklisted_domains );
foreach ( $blacklisted_domains as $blacklisted_domain ) {
// Use a regex to match the domain or subdomain
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
if ( preg_match( $pattern, $domain ) ) {
return blacklist_fail_response();
// Check if the entry starts with '/', then consider regex handling
if (strpos($blacklisted_domain, '/') === 0) {
if (@preg_match($blacklisted_domain, $domain)) {
return blacklist_fail_response();
}
} else {
// Otherwise treat as plain domain (old behavior)
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
if ( preg_match( $pattern, $domain ) ) {
return blacklist_fail_response();
}
}
}
}
@@ -126,4 +133,4 @@ function better_blacklist_process_form() {
}
echo "</ul>";
}
}
}