Account for local urls with an @
This commit is contained in:
parent
7ef6cdb7ee
commit
738208b70d
2 changed files with 20 additions and 10 deletions
|
@ -169,14 +169,14 @@ add_filter(
|
|||
$username = $m[1];
|
||||
$domain = $m[2];
|
||||
} else {
|
||||
$p = parse_url( $actor );
|
||||
$p = wp_parse_url( $actor );
|
||||
if ( $p ) {
|
||||
if ( isset( $p['host'] ) ) {
|
||||
$domain = $p['host'];
|
||||
}
|
||||
if ( isset( $p['path'] ) ) {
|
||||
$path_parts = explode( '/', trim( $p['path'], '/' ) );
|
||||
$username = array_pop( $path_parts );
|
||||
$username = ltrim( array_pop( $path_parts ), '@' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,20 +9,30 @@ class Test_Functions extends ActivityPub_TestCase_Cache_HTTP {
|
|||
$this->assertEquals( 'https://notiz.blog/author/matthias-pfefferle/', $metadata['url'] );
|
||||
$this->assertEquals( 'pfefferle', $metadata['preferredUsername'] );
|
||||
$this->assertEquals( 'Matthias Pfefferle', $metadata['name'] );
|
||||
|
||||
}
|
||||
/**
|
||||
* @dataProvider example_actors
|
||||
*/
|
||||
public function test_get_example_metadata_by_actor( $actor, $domain, $username ) {
|
||||
add_filter( 'pre_http_request', array( $this, 'invalid_http_response' ), 8, 3 );
|
||||
$metadata = \ActivityPub\get_remote_metadata_by_actor( $actor );
|
||||
$this->assertEquals( sprintf( 'https://%s/users/%s/', $domain, $username ), $metadata['url'], $actor );
|
||||
$this->assertEquals( $username, $metadata['name'], $actor );
|
||||
remove_filter( 'pre_http_request', array( $this, 'invalid_http_response' ), 8 );
|
||||
}
|
||||
|
||||
public function example_actors() {
|
||||
$actors = array();
|
||||
foreach ( array( 'user', 'test' ) as $username ) {
|
||||
foreach ( array( 'example.org', 'example.net', 'example2.com' ) as $domain ) {
|
||||
foreach ( array( '@', '' ) as $leading_at ) {
|
||||
$metadata = \ActivityPub\get_remote_metadata_by_actor( $leading_at . $username . '@' . $domain );
|
||||
$this->assertEquals( sprintf( 'https://%s/users/%s/', $domain, $username ), $metadata['url'], $username . '@' . $domain );
|
||||
$this->assertEquals( $username, $metadata['name'], $username . '@' . $domain );
|
||||
$actors[] = array( $leading_at . $username . '@' . $domain, $domain, $username );
|
||||
}
|
||||
$metadata = \ActivityPub\get_remote_metadata_by_actor( sprintf( 'https://%s/users/%s/', $domain, $username ) );
|
||||
$this->assertEquals( sprintf( 'https://%s/users/%s/', $domain, $username ), $metadata['url'], $username . '@' . $domain );
|
||||
$this->assertEquals( $username, $metadata['name'], $username . '@' . $domain );
|
||||
$actors[] = array( sprintf( 'https://%s/users/%s/', $domain, $username ), $domain, $username );
|
||||
$actors[] = array( sprintf( 'https://%s/users/%s', $domain, $username ), $domain, $username );
|
||||
$actors[] = array( sprintf( 'https://%s/@%s', $domain, $username ), $domain, $username );
|
||||
}
|
||||
}
|
||||
remove_filter( 'pre_http_request', array( $this, 'invalid_http_response' ), 8 );
|
||||
return $actors;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue