Skip to content

Conversation

adamziel
Copy link
Collaborator

Before this PR, BlockMarkupProcessor (and BlockMarkupUrlProcessor) would lose the self-closing solidus when rewriting block attributes:

$p = new BlockMarkupUrlProcessor(
	'<!-- wp:navigation-link {"url": "https://w.org"} /-->'
);
$p->next_url();
$p->set_url('https://new-site.org', WPURL::parse('https://new-site.org'));
echo $p->__toString();
// <!-- wp:navigation-link {"url": "https://new-site.org"} -->

With this PR, the self-closing solidus is preserved:

$p = new BlockMarkupUrlProcessor(
	'<!-- wp:navigation-link {"url": "https://w.org"} /-->'
);
$p->next_url();
$p->set_url('https://new-site.org', WPURL::parse('https://new-site.org'));
echo $p->__toString();
// <!-- wp:navigation-link {"url": "https://new-site.org"} /-->

Testing instructions

CI – I've added two more test cases to prevent regressions.

@adamziel adamziel added the bug Something isn't working label Oct 10, 2025
'<!-- wp:image {"sources": ["small.png", "large.png"] } /-->'
);
$this->assertTrue( $p->next_token(), 'Failed to find the block opener' );
$this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' );
Copy link
Collaborator Author

@adamziel adamziel Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only really have a single block attribute, I'll rename this method to something more sensible such as next_array_entry_in_current_block_attribute() or so in a follow-up PR.

@adamziel adamziel merged commit 8ad758e into trunk Oct 10, 2025
22 checks passed
@adamziel adamziel deleted the keep-rewritten-block-comments-in-the-same-style branch October 10, 2025 16:10
adamziel added a commit to WordPress/wordpress-importer that referenced this pull request Oct 10, 2025
Backports [php-toolkit PR 191](WordPress/php-toolkit#191):

Before this PR, `BlockMarkupProcessor` (and `BlockMarkupUrlProcessor`) would lose the self-closing solidus when rewriting block attributes:

```php
$p = new BlockMarkupUrlProcessor(
	'<!-- wp:navigation-link {"url": "https://w.org"} /-->'
);
$p->next_url();
$p->set_url('https://new-site.org', WPURL::parse('https://new-site.org'));
echo $p->__toString();
// <!-- wp:navigation-link {"url": "https://new-site.org"} -->
```

With this PR, the self-closing solidus is preserved:

```php
$p = new BlockMarkupUrlProcessor(
	'<!-- wp:navigation-link {"url": "https://w.org"} /-->'
);
$p->next_url();
$p->set_url('https://new-site.org', WPURL::parse('https://new-site.org'));
echo $p->__toString();
// <!-- wp:navigation-link {"url": "https://new-site.org"} /-->
```

## Testing instructions

CI – the php-toolkit PR has its own tests and this WordPress importer PR also comes with an additional check to ensure self-closing blocks are preserved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant