@@ -44,15 +44,16 @@ public static function register_routes() {
4444 public static function webfinger ( $ request ) {
4545 $ resource = $ request ->get_param ( 'resource ' );
4646
47- $ matches = array ();
48- $ matched = \preg_match ( '/^acct:([^@]+)@(.+)$/ ' , $ resource , $ matches );
47+ $ matched = \str_contains ( $ resource , '@ ' );
4948
5049 if ( ! $ matched ) {
5150 return new \WP_Error ( 'activitypub_unsupported_resource ' , \__ ( 'Resource is invalid ' , 'activitypub ' ), array ( 'status ' => 400 ) );
5251 }
5352
54- $ resource_identifier = $ matches [1 ];
55- $ resource_host = $ matches [2 ];
53+ $ resource = \str_replace ( 'acct: ' , '' , $ resource );
54+
55+ $ resource_identifier = \substr ( $ resource , 0 , \strrpos ( $ resource , '@ ' ) );
56+ $ resource_host = \substr ( \strrchr ( $ resource , '@ ' ), 1 );
5657
5758 if ( \wp_parse_url ( \home_url ( '/ ' ), \PHP_URL_HOST ) !== $ resource_host ) {
5859 return new \WP_Error ( 'activitypub_wrong_host ' , \__ ( 'Resource host does not match blog host ' , 'activitypub ' ), array ( 'status ' => 404 ) );
@@ -97,7 +98,7 @@ public static function request_parameters() {
9798 $ params ['resource ' ] = array (
9899 'required ' => true ,
99100 'type ' => 'string ' ,
100- 'pattern ' => '^acct:([^@] +)@(.+)$ ' ,
101+ 'pattern ' => '^acct:(. +)@(.+)$ ' ,
101102 );
102103
103104 return $ params ;
0 commit comments