Skip to content
Merged
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
13 changes: 4 additions & 9 deletions src/View/Antlers/Language/Utilities/StringUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,10 @@ public static function containsSymbolicCharacters($text)
*/
public static function sanitizePhp($text)
{
$text = str_replace('<?php', '&lt;?php', $text);

// Also replace short tags if they're enabled.
if (ini_get('short_open_tag')) {
$xmlPlaceholder = '__XML_PLACEHOLDER'.Str::uuid();
$text = str_replace('<?xml', $xmlPlaceholder, $text);
$text = str_replace('<?', '&lt;?', $text);
$text = str_replace($xmlPlaceholder, '<?xml', $text);
}
$xmlPlaceholder = '__XML_PLACEHOLDER'.Str::uuid();
$text = str_replace('<?xml', $xmlPlaceholder, $text);
$text = str_replace('<?', '&lt;?', $text);
$text = str_replace($xmlPlaceholder, '<?xml', $text);

return $text;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Antlers/Runtime/PhpEnabledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,19 @@ public function test_disabled_php_node_inside_user_values()

GlobalRuntimeState::$allowPhpInContent = false;
}

public function test_sanitize_php_is_case_insensitive()
{
$this->assertSame('&lt;?php echo "test"; ?>', StringUtilities::sanitizePhp('<?php echo "test"; ?>'));
$this->assertSame('&lt;?PHP echo "test"; ?>', StringUtilities::sanitizePhp('<?PHP echo "test"; ?>'));
$this->assertSame('&lt;?Php echo "test"; ?>', StringUtilities::sanitizePhp('<?Php echo "test"; ?>'));
$this->assertSame('&lt;?pHp echo "test"; ?>', StringUtilities::sanitizePhp('<?pHp echo "test"; ?>'));
}

public function test_sanitize_php_handles_short_tags()
{
$this->assertSame('&lt;?= $var ?>', StringUtilities::sanitizePhp('<?= $var ?>'));
$this->assertSame('&lt;?="test"?>', StringUtilities::sanitizePhp('<?="test"?>'));
$this->assertSame("&lt;? echo 'test' ?>", StringUtilities::sanitizePhp("<? echo 'test' ?>"));
}
}
Loading