Skip to content
Open
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
3 changes: 2 additions & 1 deletion includes/rest/class-endpoint-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,8 @@ protected function mp_to_wp( $mf2 ) {
$args['post_content'] = $content['html'] ? $content['html'] :
\htmlspecialchars( $content['value'] );
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

When the content array contains HTML with an empty 'html' key (falsy value like empty string or null), this code will fall back to htmlspecialchars of the 'value' field without applying make_clickable. This creates an inconsistency where some plain text content gets auto-linked (line 835) but plain text content coming from the 'value' field in an array doesn't get auto-linked. Consider applying make_clickable to the fallback case as well to ensure consistent behavior.

Suggested change
\htmlspecialchars( $content['value'] );
\make_clickable( \htmlspecialchars( $content['value'] ) );

Copilot uses AI. Check for mistakes.
} elseif ( $content ) {
$args['post_content'] = \htmlspecialchars( $content );
// Auto-link URLs in plain text content.
$args['post_content'] = \make_clickable( \htmlspecialchars( $content ) );
}
}

Expand Down
85 changes: 84 additions & 1 deletion tests/test_endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ public function test_update_add_without_content() {
$this->assertEquals( 'bar', $tags[0]->name );
$mf2 = $this->query_source( $post->ID );
$this->assertArrayHasKey( 'published', $mf2['properties'] );
// We have confirmed it exists now compare everything but this.
// We have confirmed it exists now compare everything but these time properties.
unset( $mf2['properties']['published'] );
unset( $mf2['properties']['updated'] );
$this->assertEquals(
array(
'properties' => array(
Expand Down Expand Up @@ -815,4 +816,86 @@ function test_create_publish_default_status() {
$post = self::check_create( self::create_json_request( $input ) );
$this->assertEquals( 'publish', $post->post_status );
}

function test_create_plain_text_autolinks_urls() {
$input = array(
'type' => array( 'h-entry' ),
'properties' => array(
'content' => array( 'Check out https://example.com for more info' ),
),
);
$post = self::check_create( self::create_json_request( $input ) );
// URLs in plain text content should be auto-linked.
$this->assertStringContainsString( '<a href="https://example.com"', $post->post_content );
$this->assertStringContainsString( 'https://example.com</a>', $post->post_content );
}

function test_create_plain_text_autolinks_multiple_urls() {
$input = array(
'type' => array( 'h-entry' ),
'properties' => array(
'content' => array( 'Visit https://example.com and http://test.org today' ),
),
);
$post = self::check_create( self::create_json_request( $input ) );
// Both URLs should be auto-linked.
$this->assertStringContainsString( '<a href="https://example.com"', $post->post_content );
$this->assertStringContainsString( '<a href="http://test.org"', $post->post_content );
}

function test_create_html_content_not_autolinked() {
$input = array(
'type' => array( 'h-entry' ),
'properties' => array(
'content' => array(
array( 'html' => '<p>Visit https://example.com today</p>' ),
),
),
);
$post = self::check_create( self::create_json_request( $input ) );
// HTML content should not be auto-linked (preserved as-is).
$this->assertEquals( '<p>Visit https://example.com today</p>', $post->post_content );
}

function test_create_html_content_existing_link_preserved() {
$input = array(
'type' => array( 'h-entry' ),
'properties' => array(
'content' => array(
array( 'html' => '<p>Visit <a href="https://example.com">my site</a> today</p>' ),
),
),
);
$post = self::check_create( self::create_json_request( $input ) );
// Existing links in HTML content should be preserved.
$this->assertEquals( '<p>Visit <a href="https://example.com">my site</a> today</p>', $post->post_content );
}

function test_create_html_content_code_block_preserved() {
$input = array(
'type' => array( 'h-entry' ),
'properties' => array(
'content' => array(
array( 'html' => '<p>Example: <code>https://example.com/api</code></p>' ),
),
),
);
$post = self::check_create( self::create_json_request( $input ) );
// URLs in code blocks should not be auto-linked.
$this->assertEquals( '<p>Example: <code>https://example.com/api</code></p>', $post->post_content );
}

function test_create_html_content_pre_block_preserved() {
$input = array(
'type' => array( 'h-entry' ),
'properties' => array(
'content' => array(
array( 'html' => '<pre>curl https://example.com/api</pre>' ),
),
),
);
$post = self::check_create( self::create_json_request( $input ) );
// URLs in pre blocks should not be auto-linked.
$this->assertEquals( '<pre>curl https://example.com/api</pre>', $post->post_content );
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

Consider adding a test case for content with an array structure where the 'html' key is empty or falsy, forcing fallback to the 'value' field. This would verify that URLs in plain text content are consistently auto-linked regardless of whether content is provided as a string or as an array with a 'value' field.

Copilot uses AI. Check for mistakes.
}
}