Skip to content

Commit ef3a596

Browse files
authored
PHP 8.1 (#152)
* update ci builds to include php 8.1 * fix null to preg_replace() * handle null sanitise * fix cs
1 parent 853d910 commit ef3a596

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
matrix:
1717
php-version:
1818
- '8.0'
19+
- '8.1'
1920
steps:
2021
- uses: actions/checkout@v2
2122

src/Writer/Xml/XmlFormatter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ class XmlFormatter
1414
* @see http://www.phpwact.org/php/i18n/charsets#common_problem_areas_with_utf-8
1515
* @see http://www.xiven.com/weblog/2013/08/30/PHPInvalidUTF8InXMLRevisited
1616
*/
17-
public static function sanitise(string|null $string): string
17+
public static function sanitise(string|null $value): string
1818
{
19+
if ($value === null) {
20+
return '';
21+
}
22+
1923
// Only allow Tab (9), LF (10), CR (13), Space (32) - 55295, 57344 - 65533, 65536 - 1114111.
20-
return preg_replace('/[^\x{0009}\x{000A}\x{000D}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', ' ', $string);
24+
return preg_replace('/[^\x{0009}\x{000A}\x{000D}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', ' ', $value);
2125
}
2226

2327
// Convert a boolean into a string for use in XML output.

tests/Writer/Xml/XmlFormatterTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@
1111

1212
class XmlFormatterTest extends TestCase
1313
{
14-
public function test_sanitise(): void
14+
/**
15+
* @dataProvider sanitise_data_provider
16+
*
17+
* @param mixed $value
18+
* @param mixed $expectedResult
19+
*/
20+
public function test_sanitise($value, $expectedResult): void
1521
{
16-
$invalidChar = chr(30); // Record Separator.
22+
$this->assertSame($expectedResult, XmlFormatter::sanitise($value));
23+
}
1724

18-
$this->assertSame('Foo Bar', XmlFormatter::sanitise('Foo' . $invalidChar . 'Bar'));
25+
public function sanitise_data_provider(): iterable
26+
{
27+
return [
28+
'null' => [null, ''],
29+
'record separator' => ['Foo' . chr(30) . 'Bar', 'Foo Bar'],
30+
];
1931
}
2032

2133
/**

0 commit comments

Comments
 (0)