Commit 6a253804 authored by Kevin Porras's avatar Kevin Porras
Browse files

Merge branch 'blockquote-parsing-issues' into '8.x-1.x'

Fixed incorrect content parsing of <blockquote> tags.

See merge request !31
parents c7339d36 e6481eb7
......@@ -26,11 +26,13 @@ class UwBlockquote extends UwContentComplete {
// The iterator should already contain only blockquote items.
// We just need to add quote and attribution values here.
$block_quotes = $this->parser->getBlockquotes($new_rows[0][$content_col]);
foreach ($new_rows as $delta => &$row) {
$row['quote'] = $block_quotes[$delta]['content'];
$row['attribution'] = $block_quotes[$delta]['attribution'];
$block_quote = $this->parser->getBlockquotes($row[$content_col]);
if (empty($block_quote)) {
continue;
}
$row['quote'] = $block_quote[0]['content'];
$row['attribution'] = $block_quote[0]['attribution'];
}
// Return iterator with new rows.
......@@ -41,7 +43,7 @@ class UwBlockquote extends UwContentComplete {
* {@inheritdoc}
*/
protected function isApplicable($content) {
return preg_match("/<blockquote.*.blockquote*>/Us", $content);
return preg_match("/<blockquote.*blockquote.*>/Us", $content);
}
}
......@@ -49,11 +49,22 @@ trait UwMigrateTrait {
* @return string
* Regex pattern.
*
* @see https://regex101.com/r/aOyJLl/1
* @see https://regex101.com/r/FOibAM/1
*/
public function getTagsRegex() {
$tags = implode('|', array_keys($this->getTagsMapping()));
return "/<({$tags}).*(\/\s*>|({$tags}).*>)/Us";
$tags = array_keys($this->getTagsMapping());
// Blockquote can't be self-closed tag.
$self = array_diff($tags, ['blockquote']);
return '/<' . $this->orGroup($self) . '.*\/\s*>|<' . $this->orGroup($tags) . '>.*<\/.*' . $this->orGroup($tags) . '\s*>/Us';
}
/**
* Helper to create regex OR group from array of items.
*/
public function orGroup($items) {
return '(' . implode('|', $items) . ')';
}
/**
......
......@@ -109,15 +109,17 @@ class UwMigrateContentParserTest extends TestCase {
'<test data-id="906"/>
<cktimeline data-timeline-id="123" />
<ckcalltoaction data-calltoaction-nid="123"/>
<cktwitter>text</cktwitter>
<cktwitter value="text" / >
<ckcalltoaction data-calltoaction-nid="567"/>
<uwvideo href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"/>',
<uwvideo href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"/>
<blockquote><img src="test.png" /><p>Some text.</p></blockquote>',
[
'<cktimeline data-timeline-id="123" />',
'<ckcalltoaction data-calltoaction-nid="123"/>',
'<cktwitter>text</cktwitter>',
'<cktwitter value="text" / >',
'<ckcalltoaction data-calltoaction-nid="567"/>',
'<uwvideo href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"/>',
'<blockquote><img src="test.png" /><p>Some text.</p></blockquote>'
],
],
];
......
Supports Markdown
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