Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of invalid root class names #128

Merged
merged 1 commit into from
Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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