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

Conversation

jkotalik
Copy link
Contributor

Fixes #446 using part of #533

@jkotalik jkotalik requested a review from Tratcher July 15, 2017 01:18
@Tratcher Tratcher added this to the 2.1.0 milestone Jul 17, 2017
@Tratcher
Copy link
Member

Remvoes :-)

@Tratcher
Copy link
Member

Do a quick sanity test on the setters while you're here.
#446 (comment)
https://github.com/aspnet/Mvc/blob/9342cb0ab78add8c527edcbc4c0988edc96f01e3/src/Microsoft.AspNet.Mvc.Core/FileResult.cs#L81

See if it should be adding quotes.

@Tratcher
Copy link
Member

@jkotalik jkotalik changed the title Remvoes quotes from ContentDispositonHeaderValue Name and FileName Removes quotes from ContentDispositonHeaderValue Name and FileName Jul 17, 2017
@Eilon Eilon closed this Jul 17, 2017
@Eilon Eilon reopened this Jul 17, 2017
@dnfclas
Copy link

dnfclas commented Jul 17, 2017

@jkotalik, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, .NET Foundation Pull Request Bot


var result = ContentDispositionHeaderValue.Parse(contentDispositionLine);
result.Name = "hello";
result.FileName = "\"example.png\"";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant what happens when you set a value that requires quotes, like "my file name with spaces.txt"

}

[Fact]
public void HeaderNamesWithQuotes_CheckSettersToNotHaveQuotes()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that the test I wanted already exists:

public void FileName_NeedsEncoding_EncodedAndDecodedCorrectly()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this, it's redundant

@jkotalik
Copy link
Contributor Author

@Tratcher This good to go?

public StringSegment Name
{
get { return GetName(NameString); }
get { return HeaderUtilities.RemoveQuotes(GetName(NameString)); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason we do this every time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How often will the getter be called @Tratcher ?We can store a local copy after RemoveQuotes has been called once, but it would cause a bit of clutter because only Name and FileName would have these local copies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual data is stored in the Parameters collection and is directly modifiable. This is just a convenience accessor. Any attempt at caching would have to check that the underlying version hadn't changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not often. Don't optimize it prematurely.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also turning the StringSegment into a string and back into a StringSegment negating the benefits. GetName should take a StringSegment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should accept and return a StringSegment. At least there'd be no allocations then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetName takes a constant key. It doesn't manipulate that value, it uses it for a lookup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't they leading with a _?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are all private const

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants, not variables


// Gets a parameter of the given name and attempts to decode it if necessary.
// Returns null if the parameter is not present or the raw value if the encoding is incorrect.
private string GetName(string parameter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 363 can remove the ToString() now

@jkotalik jkotalik merged commit a8270a4 into dev Jul 27, 2017
@jkotalik jkotalik deleted the jkotalik/CDHV branch July 27, 2017 19:45
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