1 common.test CommonXssUnitTestCase::testInvalidMultiByte()

Check that invalid multi-byte sequences are rejected.

File

core/modules/simpletest/tests/common.test, line 491
Tests for common.inc functionality.

Class

CommonXssUnitTestCase
Tests for check_plain(), filter_xss(), format_string(), and check_url().

Code

function testInvalidMultiByte() {
  // Ignore PHP 8.0+ null deprecations.
  $text = check_plain(NULL);
  $this->assertEqual($text, '', 'check_plain() casts null to string');
  $text = check_plain(FALSE);
  $this->assertEqual($text, '', 'check_plain() casts boolean to string');
  // cspell:disable
  $text = filter_xss("Fooÿñ");
  $this->assertEqual($text, "Fooÿñ", 'filter_xss() accepts valid sequence Fooÿñ');
  $text = check_plain("Fooÿñ");
  $this->assertEqual($text, "Fooÿñ", 'check_plain() accepts valid sequence "Fooÿñ"');
  // cspell:enable
  $text = filter_xss("Foo\xC0barbaz");
  $this->assertEqual($text, '', 'filter_xss() rejects invalid sequence "Foo\xC0barbaz"');
  // Ignore invalid multibyte sequence warning.
  $text = @check_plain("Foo\xC0barbaz");
  $this->assertEqual($text, '', 'check_plain() rejects invalid sequence "Foo\xC0barbaz"');
  // Ignore invalid multibyte sequence warning.
  $text = @check_plain("\xc2\"");
  $this->assertEqual($text, '', 'check_plain() rejects invalid sequence "\xc2\""');
}