File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed
Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 44
55namespace SimpleSAML \XML \Assert ;
66
7+ use SimpleSAML \XMLSchema \Exception \SchemaViolationException ;
8+
79/**
810 * @package simplesamlphp/xml-common
911 */
@@ -15,5 +17,10 @@ trait StringTrait
1517 */
1618 protected static function validString (string $ value , string $ message = '' ): void
1719 {
20+ Assert::regex (
21+ $ value ,
22+ '/^[\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x{10000}-\x{10FFFF}]*$/u ' ,
23+ SchemaViolationException::class,
24+ );
1825 }
1926}
Original file line number Diff line number Diff line change 44
55namespace SimpleSAML \XMLSchema \Type ;
66
7+ use SimpleSAML \XML \Assert \Assert ;
8+ use SimpleSAML \XMLSchema \Exception \SchemaViolationException ;
79use SimpleSAML \XMLSchema \Type \Interface \AbstractAnySimpleType ;
810
911/**
1214class StringValue extends AbstractAnySimpleType
1315{
1416 public const string SCHEMA_TYPE = 'string ' ;
17+
18+
19+ /**
20+ * Validate the value.
21+ *
22+ * @param string $value
23+ * @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
24+ */
25+ protected function validateValue (string $ value ): void
26+ {
27+ Assert::validString ($ value , SchemaViolationException::class);
28+ }
1529}
Original file line number Diff line number Diff line change 1010use SimpleSAML \Assert \AssertionFailedException ;
1111use SimpleSAML \XML \Assert \Assert ;
1212
13+ use function chr ;
14+
1315/**
1416 * Class \SimpleSAML\Test\XML\Assert\StringTest
1517 *
@@ -42,6 +44,8 @@ public static function provideString(): array
4244 return [
4345 'preserve spaces ' => [true , ' Snoopy ' ],
4446 'replace whitespace ' => [true , " Snoopy \t\n\rrulez " ],
47+ 'html ' => [true , "<em>SimpleSAMLphp</em> " ],
48+ 'invalid character ' => [false , "Valid text with " . chr (0 ) . " invalid null byte " ],
4549 ];
4650 }
4751}
You can’t perform that action at this time.
0 commit comments