[Core] Fix implicit conversion from null Uri to ImageSource #1253
Conversation
@@ -56,6 +56,15 @@ public void TestImplicitFileConversion () | |||
} | |||
|
|||
[Test] | |||
public void TestImplicitStringConversionWhenNull() |
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.
This test (where the input is null
) seemed to be completely missing, so I added it. Note that I am only asserting the existing behavior here - I don't actually agree with the behavior, but it is what it is.
@@ -74,10 +83,19 @@ public void TestImplicitStringUriConversion () | |||
} | |||
|
|||
[Test] | |||
public void TestImplicitUriConversionWhenNull() |
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.
This is the companion test which was previously failing, but now passes. Again, I don't agree with the behavior, but I made it match the existing behavior for null
strings.
Hi @kentcb, congrats on your first PR ! 🎉 The PR looks right, but we should decide if the current behavior is right (and accept your fix) or wrong (and fix the conversion from null string so it returns a null ImageSource). As you stated, that behavior wasn't tested, and that means no one really thought about it that much. I'm leaning toward fixing the current behavior if the current renderers behave the same way with a @jassmith could you provide your input here ? Thx |
@StephaneDelcroix yeah, as insinuated by my comments, I'd much rather the behavior of |
@kentcb we had a quick discussion about this with the team. If a FileImageSource pointing to null behave the same on the renderers as a null ImageSource, it's better to go that route. Could you please test that and update your patch? thanks |
@StephaneDelcroix I'm afraid I have nothing but questions and problems now...
|
|
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.
Hi @kentcb can you rebase so we can run the build on CI, it has a expired certificate.
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.
Lets rebase this ourselves and merge it
@@ -105,6 +105,9 @@ public static ImageSource FromUri(Uri uri) | |||
|
|||
public static implicit operator ImageSource(Uri uri) | |||
{ | |||
if (uri == null) | |||
return FromFile(null); |
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.
should return null
manually merged |
Description of Change
Ensure the implicit conversion from
Uri
toImageSource
exhibits the same behavior as implicitly converting fromstring
toImageSource
in the case where the input isnull
.Bugs Fixed
Currently, implicitly converting a
null
Uri
to anImageSource
is throwing aNullReferenceException
. This PR fixes that.API Changes
None
Behavioral Changes
No longer any need to work around the bug like this:
One can now just do this:
PR Checklist