@@ -181,9 +181,9 @@ public function getType(Type $inputType, ?Type $filterType, ?Type $flagsType): T
181181 $ type = $ this ->applyRangeOptions ($ type , $ options , $ defaultType );
182182
183183 if (
184- $ inputType ->isNonEmptyString ()->yes ()
184+ !$ this ->canStringBeSanitized ($ filterValue , $ flagsType )
185+ && $ inputType ->isNonEmptyString ()->yes ()
185186 && $ type ->isString ()->yes ()
186- && $ this ->canStringBeSanitized ($ filterValue , $ flagsType )->no ()
187187 ) {
188188 $ accessory = new AccessoryNonEmptyStringType ();
189189 if ($ inputType ->isNonFalsyString ()->yes ()) {
@@ -406,7 +406,7 @@ private function determineExactType(Type $in, int $filterValue, Type $defaultTyp
406406 $ useDefaultType = true ;
407407 }
408408
409- if ($ this ->canStringBeSanitized ($ filterValue , $ flagsType)-> no ( )) {
409+ if (! $ this ->canStringBeSanitized ($ filterValue , $ flagsType )) {
410410 $ stringType = $ inputType ->toString ();
411411 } else {
412412 $ stringType = TypeCombinator ::union (
@@ -572,22 +572,27 @@ private function getFlagsValue(Type $exprType): Type
572572 );
573573 }
574574
575- private function canStringBeSanitized (int $ filterValue , ?Type $ flagsType ): TrinaryLogic
575+ private function canStringBeSanitized (int $ filterValue , ?Type $ flagsType ): bool
576576 {
577577 // If it is a validation filter, the string will not be changed
578578 if ($ this ->isValidationFilter ($ filterValue )) {
579- return TrinaryLogic :: createNo () ;
579+ return false ;
580580 }
581581
582582 // FILTER_DEFAULT will not sanitize, unless it has FILTER_FLAG_STRIP_LOW,
583583 // FILTER_FLAG_STRIP_HIGH, or FILTER_FLAG_STRIP_BACKTICK
584584 if ($ filterValue === $ this ->getConstant ('FILTER_DEFAULT ' )) {
585- return $ this ->hasFlag ('FILTER_FLAG_STRIP_LOW ' , $ flagsType )
585+ $ hasStripFlags = $ this ->hasFlag ('FILTER_FLAG_STRIP_LOW ' , $ flagsType )
586586 ->or ($ this ->hasFlag ('FILTER_FLAG_STRIP_HIGH ' , $ flagsType ))
587587 ->or ($ this ->hasFlag ('FILTER_FLAG_STRIP_BACKTICK ' , $ flagsType ));
588+ if ($ hasStripFlags ->maybe ()) {
589+ // Too complicated, considering strip flags are not defined (default behavior).
590+ return false ;
591+ }
592+ return $ hasStripFlags ->yes ();
588593 }
589594
590- return TrinaryLogic :: createYes () ;
595+ return true ;
591596 }
592597
593598 private function isValidationFilter (int $ filterValue ): bool
0 commit comments