Skip to content

Commit fb0214f

Browse files
authored
Merge branch 'main' into dev/issue249
2 parents f92cc52 + 7daaefd commit fb0214f

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

Mf2/Parser.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ public function resolveUrl($url) {
598598
* @return string|null the parsed value or null if value-class or -title aren’t in use
599599
*/
600600
public function parseValueClassTitle(\DOMElement $e, $separator = '') {
601-
$valueClassElements = $this->xpath->query('./*[contains(concat(" ", @class, " "), " value ")]', $e);
601+
$valueClassElements = $this->xpath->query('./*[contains(concat(" ", normalize-space(@class), " "), " value ")]', $e);
602602

603603
if ($valueClassElements->length !== 0) {
604604
// Process value-class stuff
@@ -610,7 +610,7 @@ public function parseValueClassTitle(\DOMElement $e, $separator = '') {
610610
return unicodeTrim($val);
611611
}
612612

613-
$valueTitleElements = $this->xpath->query('./*[contains(concat(" ", @class, " "), " value-title ")]', $e);
613+
$valueTitleElements = $this->xpath->query('./*[contains(concat(" ", normalize-space(@class), " "), " value-title ")]', $e);
614614

615615
if ($valueTitleElements->length !== 0) {
616616
// Process value-title stuff
@@ -698,7 +698,7 @@ public function parseU(\DOMElement $u) {
698698
*/
699699
public function parseDT(\DOMElement $dt, &$dates = array(), &$impliedTimezone = null) {
700700
// Check for value-class pattern
701-
$valueClassChildren = $this->xpath->query('./*[contains(concat(" ", @class, " "), " value ") or contains(concat(" ", @class, " "), " value-title ")]', $dt);
701+
$valueClassChildren = $this->xpath->query('./*[contains(concat(" ", normalize-space(@class), " "), " value ") or contains(concat(" ", normalize-space(@class), " "), " value-title ")]', $dt);
702702
$dtValue = false;
703703

704704
if ($valueClassChildren->length > 0) {
@@ -974,7 +974,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf =
974974
}
975975

976976
// Handle p-*
977-
foreach ($this->xpath->query('.//*[contains(concat(" ", @class) ," p-")]', $e) as $p) {
977+
foreach ($this->xpath->query('.//*[contains(concat(" ", normalize-space(@class)) ," p-")]', $e) as $p) {
978978
// element is already parsed
979979
if ($this->isElementParsed($p, 'p')) {
980980
continue;
@@ -999,7 +999,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf =
999999
}
10001000

10011001
// Handle u-*
1002-
foreach ($this->xpath->query('.//*[contains(concat(" ", @class)," u-")]', $e) as $u) {
1002+
foreach ($this->xpath->query('.//*[contains(concat(" ", normalize-space(@class))," u-")]', $e) as $u) {
10031003
// element is already parsed
10041004
if ($this->isElementParsed($u, 'u')) {
10051005
continue;
@@ -1024,7 +1024,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf =
10241024
$temp_dates = array();
10251025

10261026
// Handle dt-*
1027-
foreach ($this->xpath->query('.//*[contains(concat(" ", @class), " dt-")]', $e) as $dt) {
1027+
foreach ($this->xpath->query('.//*[contains(concat(" ", normalize-space(@class)), " dt-")]', $e) as $dt) {
10281028
// element is already parsed
10291029
if ($this->isElementParsed($dt, 'dt')) {
10301030
continue;
@@ -1059,7 +1059,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf =
10591059
}
10601060

10611061
// Handle e-*
1062-
foreach ($this->xpath->query('.//*[contains(concat(" ", @class)," e-")]', $e) as $em) {
1062+
foreach ($this->xpath->query('.//*[contains(concat(" ", normalize-space(@class))," e-")]', $e) as $em) {
10631063
// element is already parsed
10641064
if ($this->isElementParsed($em, 'e')) {
10651065
continue;
@@ -1751,15 +1751,15 @@ public function convertLegacy() {
17511751

17521752
// replace all roots
17531753
foreach ($this->classicRootMap as $old => $new) {
1754-
foreach ($xp->query('//*[contains(concat(" ", @class, " "), " ' . $old . ' ") and not(contains(concat(" ", @class, " "), " ' . $new . ' "))]') as $el) {
1754+
foreach ($xp->query('//*[contains(concat(" ", normalize-space(@class), " "), " ' . $old . ' ") and not(contains(concat(" ", normalize-space(@class), " "), " ' . $new . ' "))]') as $el) {
17551755
$el->setAttribute('class', $el->getAttribute('class') . ' ' . $new);
17561756
}
17571757
}
17581758

17591759
foreach ($this->classicPropertyMap as $oldRoot => $properties) {
17601760
$newRoot = $this->classicRootMap[$oldRoot];
17611761
foreach ($properties as $old => $data) {
1762-
foreach ($xp->query('//*[contains(concat(" ", @class, " "), " ' . $oldRoot . ' ")]//*[contains(concat(" ", @class, " "), " ' . $old . ' ") and not(contains(concat(" ", @class, " "), " ' . $data['replace'] . ' "))]') as $el) {
1762+
foreach ($xp->query('//*[contains(concat(" ", normalize-space(@class), " "), " ' . $oldRoot . ' ")]//*[contains(concat(" ", normalize-space(@class), " "), " ' . $old . ' ") and not(contains(concat(" ", normalize-space(@class), " "), " ' . $data['replace'] . ' "))]') as $el) {
17631763
$el->setAttribute('class', $el->getAttribute('class') . ' ' . $data['replace']);
17641764
}
17651765
}

tests/Mf2/ParserTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,22 @@ public function testGetRootMfOnlyFindsValidElements() {
899899
$this->assertEquals('h-vendor123-name', $rootEls->item(0)->getAttribute('class'));
900900
}
901901

902+
/**
903+
* @see https://github.com/microformats/php-mf2/issues/245
904+
*/
905+
public function testNewlineBeforePrefix() {
906+
$input = <<<EOT
907+
<div class="h-entry">
908+
<h1 class="post_title__text
909+
p-name">Page Title</h1>
910+
<p class="p-summary">A summary so the p-name won't be implied. This test demonstrates p-name is not being parsed.</p>
911+
</div>
912+
EOT;
913+
$result = Mf2\parse($input);
914+
$this->assertEquals('Page Title', $result['items'][0]['properties']['name'][0]);
915+
$this->assertEquals('A summary so the p-name won\'t be implied. This test demonstrates p-name is not being parsed.', $result['items'][0]['properties']['summary'][0]);
916+
}
917+
902918
/**
903919
* @see https://github.com/microformats/php-mf2/issues/249
904920
*/

0 commit comments

Comments
 (0)