Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

[NoMerge] React to StringValues#7520

Closed
benaadams wants to merge 1 commit into
aspnet:devfrom
benaadams:react-to-stringvalues
Closed

[NoMerge] React to StringValues#7520
benaadams wants to merge 1 commit into
aspnet:devfrom
benaadams:react-to-stringvalues

Conversation

@benaadams
Copy link
Copy Markdown
Contributor

@benaadams benaadams commented Mar 21, 2018

dotnet/extensions#323 made a subtle change that causes string[] myArray = new StringValues(new string[0]) to implicitly become null.

/cc @Tratcher @rynowak

@Tratcher
Copy link
Copy Markdown
Member

@Tratcher Tratcher requested a review from dougbu March 21, 2018 19:14
@rynowak
Copy link
Copy Markdown
Member

rynowak commented Mar 21, 2018

Is this an approved breaking change?

@dougbu
Copy link
Copy Markdown
Contributor

dougbu commented Mar 21, 2018

It was my understanding that the breaking change in StringValues was going to be reversed. Is that not the case @Tratcher?

@benaadams
Copy link
Copy Markdown
Contributor Author

benaadams commented Mar 21, 2018

Currently StringValues is ambiguous and has multiple ways to represent the low counts:

Count == 0

  • null
  • string[0]

Count == 1

  • string
  • string[1]

Count == 2

  • string[2]

This means the check .Count == 0 becomes

if ((_value != null ? 1 : (_values?.Length ?? 0)) == 0)

And the cast of a .Count == 0 to an string[] can become both string[0] and null

After dotnet/extensions#323 there is a single (internal) representation for each count

Count == 0

  • null

Count == 1

  • string

Count == 2

  • string[2]

There is a fast path for .Count == 0 of .IsNull becoming

if (_value == null && _values == null)

Obviously the inverse for .Count > 0 being !value.IsNull

And the cast of a .Count == 0 to an string[] can only return null

Though, its easy enough to have it return Array.Empty<string>() instead...

@benaadams benaadams force-pushed the react-to-stringvalues branch from 5140832 to 98f1ac0 Compare March 21, 2018 20:07
@dougbu
Copy link
Copy Markdown
Contributor

dougbu commented Mar 21, 2018

We were talking about a StringValues breaking change. Now this PR seems to create a ValueProviderResult breaking change (callers can no longer iterate through the values of the empty result). I don't see how either breaking change is acceptable.

@benaadams
Copy link
Copy Markdown
Contributor Author

callers can no longer iterate through the values of the empty result

That should still be valid

@benaadams
Copy link
Copy Markdown
Contributor Author

callers can no longer iterate through the values of the empty result

Might need these two changes also
aspnet/HttpAbstractions#1010
dotnet/extensions#330

@benaadams
Copy link
Copy Markdown
Contributor Author

benaadams commented Mar 21, 2018

There were two .Count == 0 before and things broke because not both of them were handled; now there is just one and everything is the same so only one of them needs to be handled.

e.g. the follow up change in StringValues dotnet/extensions#330 now tests Assert.Empty((string[])stringValues) as per MVC rather than the other path of Assert.Null((string[])stringValues) which it was doing before

@benaadams benaadams force-pushed the react-to-stringvalues branch from a042b1b to 91ab796 Compare March 21, 2018 21:58
@benaadams
Copy link
Copy Markdown
Contributor Author

Added test fix to react to other PRs 4483843

Added temp fix while waiting for other PRs 91ab796

@Tratcher
Copy link
Copy Markdown
Member

Heads up, the original change was reverted. We'll reintroduce it more cautiously by doing full universe builds before merging.

@benaadams benaadams force-pushed the react-to-stringvalues branch from 91ab796 to 7eaacc0 Compare March 24, 2018 04:05
@benaadams benaadams changed the title React to StringValues [NoMerge] React to StringValues Mar 24, 2018
@benaadams benaadams force-pushed the react-to-stringvalues branch from 7eaacc0 to 69c5fe6 Compare March 24, 2018 06:18
@benaadams benaadams force-pushed the react-to-stringvalues branch from 69c5fe6 to 10336ef Compare March 24, 2018 08:03
@pranavkm
Copy link
Copy Markdown
Contributor

pranavkm commented Apr 3, 2018

Can this be closed?

@dougbu
Copy link
Copy Markdown
Contributor

dougbu commented Apr 3, 2018

Yes

@dougbu dougbu closed this Apr 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants