From fed4fcb5b4906bde5754562c117ab3fdcdf10181 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Tue, 13 Dec 2022 11:24:30 +0100 Subject: [PATCH] Short-circuit some more examples --- activitypub.php | 11 ++++++++++- tests/test-functions.php | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/activitypub.php b/activitypub.php index 0a5c156..b1f8ed4 100644 --- a/activitypub.php +++ b/activitypub.php @@ -180,7 +180,16 @@ add_filter( } } } - if ( rtrim( strtok( $domain, '.' ), '0123456789' ) === 'example' ) { + if ( preg_match( '/[^a-zA-Z0-9.-]/', $domain ) ) {// invalid characters + return $metadata; + } + + if ( + rtrim( strtok( $domain, '.' ), '0123456789' ) === 'example' // classic example.org domain + || preg_match( '/(my|your|our)-(domain)/', $domain ) + || preg_match( '/(test)/', $domain ) + || in_array( $username, array( 'example' ), true ) + ) { $metadata = array( 'url' => sprintf( 'https://%s/users/%s/', $domain, $username ), 'name' => $username, diff --git a/tests/test-functions.php b/tests/test-functions.php index 3887de3..81fc68f 100644 --- a/tests/test-functions.php +++ b/tests/test-functions.php @@ -24,7 +24,7 @@ class Test_Functions extends ActivityPub_TestCase_Cache_HTTP { public function example_actors() { $actors = array(); foreach ( array( 'user', 'test' ) as $username ) { - foreach ( array( 'example.org', 'example.net', 'example2.com' ) as $domain ) { + foreach ( array( 'example.org', 'example.net', 'example2.com', 'my-domain.com', 'your-domain.org', 'test.net' ) as $domain ) { foreach ( array( '@', '' ) as $leading_at ) { $actors[] = array( $leading_at . $username . '@' . $domain, $domain, $username ); } @@ -33,6 +33,9 @@ class Test_Functions extends ActivityPub_TestCase_Cache_HTTP { $actors[] = array( sprintf( 'https://%s/@%s', $domain, $username ), $domain, $username ); } } + + $actors[] = array( 'example@abc.org', 'abc.org', 'example' ); + return $actors; } }