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