Skip to content

Commit eb80840

Browse files
authored
Merge pull request #4605 from LuckyPennySoftware/4593-pascalcasenamingconvention-is-splitting-formxml-to-form-x-m-l
Correctly handling consecutive uppercase characters; fixes #4593
2 parents d9c1fbb + 4f6a57a commit eb80840

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/AutoMapper/Configuration/INamingConvention.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public string[] Split(string input)
2424
int lower = 0;
2525
for (int index = 1; index < input.Length; index++)
2626
{
27-
if (char.IsUpper(input[index]))
27+
if (char.IsUpper(input[index]) &&
28+
(!char.IsUpper(input[index - 1]) ||
29+
(index + 1 < input.Length && !char.IsUpper(input[index + 1]))))
2830
{
2931
result ??= [];
3032
result.Add(input[lower..index]);

src/UnitTests/Bug/NamingConventions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ public void Should_map_from_pascal_to_lower()
104104
_dario.JaSeZovemImenom.ShouldBe("foo");
105105
}
106106
}
107+
public class PascalCaseAcronymInPropertyName : AutoMapperSpecBase
108+
{
109+
class Source { public Inner Form { get; set; } }
110+
class Inner { public int XML { get; set; } }
111+
class Dest { public int FormXML { get; set; } }
112+
113+
protected override MapperConfiguration CreateConfiguration() => new(cfg =>
114+
cfg.CreateMap<Source, Dest>());
115+
116+
[Fact]
117+
public void Should_flatten_acronym_property()
118+
{
119+
var result = Mapper.Map<Dest>(new Source { Form = new Inner { XML = 42 } });
120+
result.FormXML.ShouldBe(42);
121+
}
122+
}
107123

108124
public class When_mapping_with_lowercase_naming_conventions_two_ways : AutoMapperSpecBase
109125
{

0 commit comments

Comments
 (0)