diff --git a/src/validators/string.rs b/src/validators/string.rs index a1f7765ad..985aa1068 100644 --- a/src/validators/string.rs +++ b/src/validators/string.rs @@ -200,7 +200,7 @@ impl StrConstrainedValidator { } // whether any of the constraints/customisations are actually enabled - // except strict which can be set on StrValidator + // except strict and coerce_numbers_to_str which can be set on StrValidator fn has_constraints_set(&self) -> bool { self.pattern.is_some() || self.max_length.is_some() @@ -208,7 +208,6 @@ impl StrConstrainedValidator { || self.strip_whitespace || self.to_lower || self.to_upper - || self.coerce_numbers_to_str } } diff --git a/tests/validators/test_string.py b/tests/validators/test_string.py index 50afc878a..ae5ced611 100644 --- a/tests/validators/test_string.py +++ b/tests/validators/test_string.py @@ -286,6 +286,14 @@ class StrSubclass(str): assert not isinstance(v.validate_python(StrSubclass(''), strict=True), StrSubclass) +@pytest.mark.parametrize('string', [True, False]) +def test_coerce_numbers_to_str_with_invalid_unicode_character(string) -> None: + config = core_schema.CoreConfig(coerce_numbers_to_str=True) + + v = SchemaValidator(core_schema.str_schema(strict=string), config) + assert v.validate_python('\ud835') == '\ud835' + + def test_coerce_numbers_to_str_disabled_in_strict_mode() -> None: config = core_schema.CoreConfig(coerce_numbers_to_str=True)