mirror of
https://github.com/Frumph/comic-easel.git
synced 2026-08-24 12:02:53 -04:00
e65602cba5
Co-authored-by: gpt-5.6-sol <noreply@openai.com>
75 lines
2.6 KiB
PHP
75 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Late output escaping for public title and taxonomy surfaces.
|
|
*/
|
|
class OutputEscapingTest extends CE_TestCase {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
self::loadPluginFile( 'functions/library.php' );
|
|
self::loadPluginFile( 'functions/shortcodes.php' );
|
|
self::loadPluginFile( 'functions/redirects.php' );
|
|
}
|
|
|
|
public function testTitleAttributeCannotCreateANewAttribute() {
|
|
CE_Test_State::$titles[7] = 'Boom" onmouseover="alert(1) & Co';
|
|
|
|
$escaped = ceo_title_for_attribute( 7 );
|
|
|
|
$this->assertSame( 'Boom" onmouseover="alert(1) & Co', $escaped );
|
|
$this->assertStringNotContainsString( '" onmouseover="', $escaped );
|
|
}
|
|
|
|
public function testHtmlTitleUsesKsesWithoutDoubleEncodingEntities() {
|
|
CE_Test_State::$titles[7] = '<em>A & B</em><img src=x onerror=alert(1)>';
|
|
|
|
$this->assertSame(
|
|
CE_KSES_SENTINEL . '<em>A & B</em><img src=x onerror=alert(1)>',
|
|
ceo_title_for_html( 7 )
|
|
);
|
|
$this->assertSame(
|
|
array( '<em>A & B</em><img src=x onerror=alert(1)>' ),
|
|
CE_Test_State::$kses_calls
|
|
);
|
|
}
|
|
|
|
public function testCastOutputEscapesSlugAttributesAndFiltersVisibleMarkup() {
|
|
$character = new stdClass();
|
|
$character->slug = 'hero" onclick="alert(1)';
|
|
$character->name = '<em>Hero & Friend</em><script>alert(1)</script>';
|
|
$character->description = '<strong>Bio</strong><script>alert(2)</script>';
|
|
$character->count = 1;
|
|
|
|
$output = ceo_cast_display( $character, false, true );
|
|
|
|
$this->assertStringContainsString( 'character-hero" onclick="alert(1)', $output );
|
|
$this->assertStringNotContainsString( 'class="cast-pic character-hero" onclick="', $output );
|
|
$this->assertStringContainsString( CE_KSES_SENTINEL . $character->name, $output );
|
|
$this->assertStringContainsString( CE_KSES_SENTINEL . $character->description, $output );
|
|
}
|
|
|
|
public function testUnknownCharacterShortcodeEscapesTheReflectedName() {
|
|
$output = ceo_cast_page(
|
|
array( 'character' => '<img src=x onerror=alert(1)>' )
|
|
);
|
|
|
|
$this->assertStringContainsString( '<img src=x onerror=alert(1)>', $output );
|
|
$this->assertStringNotContainsString( '<img', $output );
|
|
}
|
|
|
|
public function testBuyComicMessagesPreserveAllowedMarkupThroughKses() {
|
|
$_REQUEST['action'] = 'thankyou';
|
|
$message = '<em>Thanks & welcome</em><script>alert(1)</script>';
|
|
|
|
try {
|
|
$output = ceo_display_buycomic( array( 'thanks' => $message ) );
|
|
} finally {
|
|
unset( $_REQUEST['action'] );
|
|
}
|
|
|
|
$this->assertStringContainsString( CE_KSES_SENTINEL . $message, $output );
|
|
$this->assertContains( $message, CE_Test_State::$kses_calls );
|
|
}
|
|
}
|