diff --git a/src/AutoMapper/Configuration/INamingConvention.cs b/src/AutoMapper/Configuration/INamingConvention.cs index dad9164465..22418c7656 100644 --- a/src/AutoMapper/Configuration/INamingConvention.cs +++ b/src/AutoMapper/Configuration/INamingConvention.cs @@ -24,7 +24,9 @@ public string[] Split(string input) int lower = 0; for (int index = 1; index < input.Length; index++) { - if (char.IsUpper(input[index])) + if (char.IsUpper(input[index]) && + (!char.IsUpper(input[index - 1]) || + (index + 1 < input.Length && !char.IsUpper(input[index + 1])))) { result ??= []; result.Add(input[lower..index]); diff --git a/src/UnitTests/Bug/NamingConventions.cs b/src/UnitTests/Bug/NamingConventions.cs index 1344b0c8d8..79d85d9d40 100644 --- a/src/UnitTests/Bug/NamingConventions.cs +++ b/src/UnitTests/Bug/NamingConventions.cs @@ -104,6 +104,22 @@ public void Should_map_from_pascal_to_lower() _dario.JaSeZovemImenom.ShouldBe("foo"); } } +public class PascalCaseAcronymInPropertyName : AutoMapperSpecBase +{ + class Source { public Inner Form { get; set; } } + class Inner { public int XML { get; set; } } + class Dest { public int FormXML { get; set; } } + + protected override MapperConfiguration CreateConfiguration() => new(cfg => + cfg.CreateMap()); + + [Fact] + public void Should_flatten_acronym_property() + { + var result = Mapper.Map(new Source { Form = new Inner { XML = 42 } }); + result.FormXML.ShouldBe(42); + } +} public class When_mapping_with_lowercase_naming_conventions_two_ways : AutoMapperSpecBase {