Browse Source

fix for html

main
Aaron Parecki 6 years ago
parent
commit
c6c869a75a
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 15 additions and 1 deletions
  1. +1
    -1
      lib/Telegraph/FindLinks.php
  2. +14
    -0
      tests/FindLinksTest.php

+ 1
- 1
lib/Telegraph/FindLinks.php View File

@ -45,7 +45,7 @@ class FindLinks {
* @return mixed array of links in text block. * @return mixed array of links in text block.
*/ */
public static function inHTML($html) { public static function inHTML($html) {
if(!is_string($input)) return [];
if(!is_string($html)) return [];
$doc = new DOMDocument(); $doc = new DOMDocument();
libxml_use_internal_errors(true); # suppress parse errors and warnings libxml_use_internal_errors(true); # suppress parse errors and warnings

+ 14
- 0
tests/FindLinksTest.php View File

@ -38,5 +38,19 @@ class FindLinksTest extends PHPUnit_Framework_TestCase {
$this->assertContains('http://example.html/', $links); $this->assertContains('http://example.html/', $links);
} }
public function testFindLinksInXRayResult() {
$data = json_decode('
{"data":{"type":"entry","published":"2018-06-19T14:32:44-07:00","url":"https://aaronparecki.com/2018/06/19/12/indiewebsummit","category":["indieweb"],"syndication":["https://twitter.com/aaronpk/status/1009187255204732928"],"content":{"text":"I\'m excited to announce that @namedotcom is our newest sponsor of @IndieWebSummit and they\'ll be joining us next week! It\'s not too late to register! \ud83d\udd1c https://2018.indieweb.org","html":"I\'m excited to announce that <a href=\"https://twitter.com/namedotcom\">@namedotcom</a> is our newest sponsor of <a href=\"https://twitter.com/IndieWebSummit\">@IndieWebSummit</a> and they\'ll be joining us next week! It\'s not too late to register! <a href=\"https://aaronparecki.com/emoji/%F0%9F%94%9C\">\ud83d\udd1c</a> <a href=\"https://2018.indieweb.org\">https://2018.indieweb.org</a>"},"author":{"type":"card","name":"Aaron Parecki","url":"https://aaronparecki.com/","photo":"https://aaronparecki.com/images/profile.jpg"}},"url":"https://aaronparecki.com/2018/06/19/12/indiewebsummit","code":200}
', true);
unset($data['data']['author']);
$links = FindLinks::all($data['data']);
$this->assertContains('https://aaronparecki.com/2018/06/19/12/indiewebsummit', $links);
$this->assertContains('https://twitter.com/aaronpk/status/1009187255204732928', $links);
$this->assertContains('https://2018.indieweb.org', $links);
$this->assertContains('https://twitter.com/namedotcom', $links);
$this->assertContains('https://twitter.com/IndieWebSummit', $links);
$this->assertContains('https://aaronparecki.com/emoji/%F0%9F%94%9C', $links);
}
} }

Loading…
Cancel
Save