Browse Source

parse redirect uri for h-app

parse from both link tags and the u-redirect-uri property
pull/72/head v1.4.30
Aaron Parecki 6 years ago
parent
commit
417cc1b3cc
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 22 additions and 7 deletions
  1. +10
    -0
      lib/XRay/Formats/Mf2.php
  2. +7
    -6
      tests/ParseTest.php
  3. +5
    -1
      tests/data/source.example.com/h-app

+ 10
- 0
lib/XRay/Formats/Mf2.php View File

@ -571,10 +571,20 @@ class Mf2 extends Format {
];
self::collectSingleValues(['name'], ['url','logo'], $item, $url, $data);
self::collectArrayURLValues(['redirect-uri'], $item, $data, $refs, $http);
if(!isset($data['url']))
$data['url'] = $url;
if(isset($mf2['rels']['redirect_uri'])) {
if(!isset($data['redirect-uri'])) $data['redirect-uri'] = [];
$data['redirect-uri'] = array_merge($data['redirect-uri'], $mf2['rels']['redirect_uri']);
}
if(isset($data['redirect-uri'])) {
$data['redirect-uri'] = array_values(array_unique($data['redirect-uri']));
}
$response = [
'data' => $data
];

+ 7
- 6
tests/ParseTest.php View File

@ -638,12 +638,13 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('app', $data->data->type);
$this->assertEquals('http://source.example.com/images/quill.png', $data->data->logo);
$this->assertEquals('Quill', $data->data->name);
$this->assertEquals($url, $data->data->url);
$this->assertObjectNotHasAttribute('photo', $data->data);
$data = json_decode($body, true);
$this->assertEquals('app', $data['data']['type']);
$this->assertEquals('http://source.example.com/images/quill.png', $data['data']['logo']);
$this->assertEquals('Quill', $data['data']['name']);
$this->assertEquals($url, $data['data']['url']);
$this->assertEquals(['http://source.example.com/redirect1','http://source.example.com/redirect2'], $data['data']['redirect-uri']);
$this->assertArrayNotHasKey('photo', $data['data']);
}
public function testHXApp() {

+ 5
- 1
tests/data/source.example.com/h-app View File

@ -7,8 +7,12 @@ Connection: keep-alive
<html>
<head>
<title>Test</title>
<link rel="redirect_uri" href="/redirect1">
<link rel="redirect_uri" href="/redirect2">
</head>
<body class="h-app">
<img src="/images/quill.png" class="u-logo p-name" alt="Quill">
<img src="/images/quill.png" class="u-logo">
<a href="/h-app" class="u-url p-name">Quill</a>
<a href="/redirect1" class="u-redirect-uri"></a>
</body>
</html>

Loading…
Cancel
Save