New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: prevent collection mapping using invalid length property #1108
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1108 +/- ##
==========================================
+ Coverage 91.38% 91.39% +0.01%
==========================================
Files 221 221
Lines 7300 7301 +1
Branches 931 931
==========================================
+ Hits 6671 6673 +2
+ Misses 411 410 -1
Partials 218 218 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking into this and contributing a fix!
Doesn't a similar problem exist in EnumerableMappingBuilder.BuildCustomTypeMapping
with the EnsureCapacityBuilder.TryBuildEnsureCapacity(ctx)
call using the old / wrong source count property? IMO the best solution would be to create a new CollectionInfos
instance when overwriting the source type and passing that directly to TryBuildEnsureCapacity
.
I think also DictionaryMappingBuilder.BuildCustomTypeMapping
has a potential similar problem... I don't think it is a real problem there now (as it is always the Count property for dictionary), but I don't think the code now is really correct.
src/Riok.Mapperly/Descriptors/MappingBuilders/EnumerableMappingBuilder.cs
Outdated
Show resolved
Hide resolved
5cbb0c0
to
6b57fef
Compare
I opted to return
|
6b57fef
to
647b84c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates, one small feedback point.
src/Riok.Mapperly/Descriptors/Enumerables/EnsureCapacity/EnsureCapacityBuilder.cs
Show resolved
Hide resolved
60ca6a0
to
6dc09cb
Compare
🎉 This PR is included in version 3.4.0-next.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 3.4.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Fix bug where array to list mappings would attempt to use an invalid
Length
property on the loweredIReadOnlyCollection
source.Fixes #1106
EnumerableToList
will always useCount
instead of the non lowered sourcesCountPropertyName
CollectionInfoBuilder
to get the newCountPropertyName
ArrayToListShouldImproveNullability
testBuildEnumerableToArrayMapping
, I think all calls to this method will always useCount
for the original and lowered types. PerhapsCountPropertyName
should be used hereChecklist