Commit 1f34c9e8 authored by Barnaby Walters's avatar Barnaby Walters

Manually merged parsertest

parents 184823a4 bb02f0ee
......@@ -730,6 +730,9 @@ class Parser {
// TODO: as it is this is not relative to only children, make this .// and rerun tests
$this->resolveChildUrls($e);
$this->removeTags($e, 'script');
$this->removeTags($e, 'style');
$html = '';
foreach ($e->childNodes as $node) {
$html .= $node->C14N();
......@@ -737,10 +740,16 @@ class Parser {
return array(
'html' => $html,
'value' => unicodeTrim($this->textContent($e))
'value' => unicodeTrim($this->innerText($e))
);
}
private function removeTags(\DOMElement &$e, $tagName) {
while(($r = $e->getElementsByTagName($tagName)) && $r->length) {
$r->item(0)->parentNode->removeChild($r->item(0));
}
}
/**
* Recursively parse microformats
*
......
......@@ -325,4 +325,50 @@ EOT;
$result = Mf2\applySrcsetUrlTransformation($srcset, $transformation);
$this->assertEquals('https://example.com/banner-HD.jpeg 2x, https://example.com/banner-phone.jpeg 100w, https://example.com/banner-phone-HD.jpeg 100w 2x', $result);
}
public function testScriptTagContentsRemovedFromTextValue() {
$input = <<<EOT
<div class="h-entry">
<div class="p-content">
<b>Hello World</b>
<script>alert("hi");</script>
</div>
</div>
EOT;
$parser = new Parser($input);
$output = $parser->parse();
$this->assertContains('h-entry', $output['items'][0]['type']);
$this->assertContains('Hello World', $output['items'][0]['properties']['content'][0]);
$this->assertNotContains('alert', $output['items'][0]['properties']['content'][0]);
}
public function testScriptTagContentsRemovedFromHTMLValue() {
$input = <<<EOT
<div class="h-entry">
<div class="e-content">
<b>Hello World</b>
<script>alert("hi");</script>
<style>body{ visibility: hidden; }</style>
<p>
<script>alert("hi");</script>
<style>body{ visibility: hidden; }</style>
</p>
</div>
</div>
EOT;
$parser = new Parser($input);
$output = $parser->parse();
$this->assertContains('h-entry', $output['items'][0]['type']);
$this->assertContains('Hello World', $output['items'][0]['properties']['content'][0]['value']);
$this->assertContains('<b>Hello World</b>', $output['items'][0]['properties']['content'][0]['html']);
# The script and style tags should be removed from both HTML and plaintext results
$this->assertNotContains('alert', $output['items'][0]['properties']['content'][0]['html']);
$this->assertNotContains('alert', $output['items'][0]['properties']['content'][0]['value']);
$this->assertNotContains('visibility', $output['items'][0]['properties']['content'][0]['html']);
$this->assertNotContains('visibility', $output['items'][0]['properties']['content'][0]['value']);
}
}
......@@ -212,9 +212,6 @@ class UrlTest extends PHPUnit_Framework_TestCase {
array('relative add host from base',
'http://www.example.com', 'server.php', 'http://www.example.com/server.php'),
array('relative add scheme host user from base',
'http://user:@www.example.com', 'server.php', 'http://user:@www.example.com/server.php'),
array('relative add scheme host pass from base',
'http://:pass@www.example.com', 'server.php', 'http://:pass@www.example.com/server.php'),
......@@ -256,6 +253,15 @@ class UrlTest extends PHPUnit_Framework_TestCase {
);
// PHP 5.4 and before returns a different result, but either are acceptable
if(PHP_MAJOR_VERSION <= 5 && PHP_MINOR_VERSION <= 4) {
$cases[] = array('relative add scheme host user from base',
'http://user:@www.example.com', 'server.php', 'http://user@www.example.com/server.php');
} else {
$cases[] = array('relative add scheme host user from base',
'http://user:@www.example.com', 'server.php', 'http://user:@www.example.com/server.php');
}
// Test cases from RFC
// http://tools.ietf.org/html/rfc3986#section-5.4
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment