1111use SimpleSAML \XMLSchema \Exception \SchemaViolationException ;
1212use SimpleSAML \XMLSchema \Type \Interface \AbstractAnySimpleType ;
1313
14+ use function rtrim ;
15+ use function strlen ;
16+ use function substr ;
17+
1418/**
1519 * @package simplesaml/xml-common
1620 */
@@ -28,7 +32,28 @@ class DateTimeValue extends AbstractAnySimpleType
2832 */
2933 protected function sanitizeValue (string $ value ): string
3034 {
31- return static ::collapseWhitespace (static ::normalizeWhitespace ($ value ));
35+ $ normalized = static ::collapseWhitespace (static ::normalizeWhitespace ($ value ));
36+
37+ // Trim any trailing zero's from the sub-seconds
38+ $ decimal = strrpos ($ normalized , '. ' );
39+ if ($ decimal !== false ) {
40+ $ timezone = strrpos ($ normalized , '+ ' ) ?? strrpos ($ normalized , '- ' ) ?? strrpos ($ normalized , 'Z ' );
41+ if ($ timezone !== false ) {
42+ $ subseconds = substr ($ normalized , $ decimal + 1 , strlen ($ normalized ) - $ timezone );
43+ } else {
44+ $ subseconds = substr ($ normalized , $ decimal + 1 );
45+ }
46+
47+ $ subseconds = rtrim ($ subseconds , '0 ' );
48+ if ($ subseconds === '' ) {
49+ return substr ($ normalized , 0 , $ decimal );
50+ }
51+ return substr ($ normalized , 0 , $ decimal + 1 )
52+ . $ subseconds
53+ . (($ timezone === false ) ? '' : substr ($ normalized , $ timezone ));
54+ }
55+
56+ return $ normalized ;
3257 }
3358
3459
0 commit comments