Skip to content

Commit

Permalink
Fix parsing of invalid root class names
Browse files Browse the repository at this point in the history
  • Loading branch information
gRegorLove committed May 29, 2017
1 parent e7c0cac commit f139131
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,10 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
// Get current µf name
$mfTypes = mfNamesFromElement($e, 'h-');

if (!$mfTypes) {
return null;
}

// Initalise var to store the representation in
$return = array();
$children = array();
Expand Down
25 changes: 25 additions & 0 deletions tests/Mf2/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,31 @@ public function testCamelCaseClassNames() {
}


/**
* @see https://github.com/indieweb/php-mf2/issues/127
*/
public function testCamelCaseRootClassNames() {
$input = '<div class="h-Entry"> <a href="https://example.com" class="u-url">content</a> </div>';
$output = Mf2\parse($input);

$this->assertEmpty($output['items']);
}


/**
* @see https://github.com/indieweb/php-mf2/issues/127
*/
public function testMisTypedRootClassNames() {
$input = '<div class="h-entry>"> <a href="https://example.com" class="u-url">content</a></div>
<div class="h-entry1>"> <a href="https://example.com" class="u-url">content</a></div>
<div class="h-👍"> <a href="https://example.com" class="u-url">content</a></div>
<div class="h-hentry_"> <a href="https://example.com" class="u-url">content</a></div>
<div class="h-"> <a href="https://example.com" class="u-url">content</a></div>';
$output = Mf2\parse($input);

$this->assertEmpty($output['items']);
}

public function testClassNameNumbers() {
$input = '<div class="h-entry"> <div class="u-column1"> <p class="p-title">Test</p> </div> </div>';
$output = Mf2\parse($input);
Expand Down

0 comments on commit f139131

Please sign in to comment.