-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Quote Multipart/Form-Data Field Names #6782
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
Quote Multipart/Form-Data Field Names #6782
Conversation
|
Should we open an issue against corefx? If corefx supports/fixes this in the future, will we have double quotes? |
|
At this point it would be a breaking change in CoreFX. This is the same behavior for |
|
I found this https://github.com/dotnet/corefx/issues/26886#issuecomment-381697212 though, this begs the question why every browser and curl wraps the name and filename fields values in quotes and .NET does not? |
SteveL-MSFT
left a comment
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.
LGTM
|
Seems it is important fix so we need to add tests. Maybe use output with |
|
@iSazonov if you can, please provide a code example... otherwise I have no clue what you are suggesting :) Since the request output is generated inside the HttpClient code, we can't really access it. Only way I can think of would be to echo the raw response back from WebListener and regex for the fields and quotes. That or create a special endpoint on WebListener and do the regex there. If you try to process the request in ASP.NET as a form, you lose the content disposition headers which is where this is stored. I'm not sure this warrants the level of effort and code it would take to make a meaningful test for it. |
|
I believe we should have tests for the uploading. |
|
@markekraus I think it would be ok to add a test to weblistener to specifically return the field names and values as raw text. Since the values are controlled by the Pester test, it should know exactly what should be returned without having to resort to regex |
|
@SteveL-MSFT The problem is the ASP.NET does not provide whether or not the feild names are quoted when you consume the response as a form. The only way to test that is to echo back the raw HTTP request as a string. |
|
@markekraus I see, so you either get just the name value pairs stripped of the quotes or the entire raw request. It seems the risk is low and the cost is high. I would be fine creating a new issue to add such a test in the future, particularly if it's useful beyond this specific issue. |
|
Added #6794 to track possible adding an echo controller to WebListener. |
@markekraus implemented WebListener so fast that I'm still amazed :-) |
|
@daxian-dbw Do you agree that we use the |
|
I don't have a strong opinion. I don't want to block people from using C# language features :) |
|
@daxian-dbw Thanks! @markekraus ConvertTo<T> uses InvariantCulture. I believe we should keep consistency. |
|
Yea. I'm not married to any particular string formater or interpolation method. So, whatever works best. |
|
We could = "\"" + ... + "\""; |
|
Sorry for wrong close. |
|
You can also choose culture with the string interpolation: FormattableString message = $"The speed of light is {speedOfLight:N3} km/s.";
string messageInInvariantCulture = FormattableString.Invariant(message);See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated |
|
I think that the double formatting superfluous here. |
|
@iSazonov Does the culture on these even matter? I'm not doing any format transformations, I'm just shoving one string inside another. |
|
I remember that we have already corrected misuses of culture in formatting. So I'm trying to be careful here. |
|
@iSazonov I'm saying that I believe the culture isn't important here because they are already strings when being interpolated and I am not performing any transformations on it. What I understand happens here is is So I'm asking.. does it even matter here? as far as I can tell, what ever string interpolation, concatenation, creation, and building method would all produce the same strings in the end because we are just dealing with combining strings and not doing any formatting or transformations (those are already done by
|
No. The discussion is about code style. Bad style is a open door for camouflaged bugs. Therefore, we require explicit curly braces in the |
|
... why is this bad style? what is wrong with |
|
@iSazonov Also, I cannot figure out how you intend to use String.Create() here. Can you provide me with an example relevant to this PR? It seems like it is overkill for string concatenation. |
|
I am very sorry for noisy. We had culture related bugs in string operations.
You could ignore this today. I hope we'll do code cleanups to reduce allocations and use the pattern too. |
|
ok.. so |
If other maintainers agree that we should always use explicit culture then yes. Previously we use + for concatinations for few arguments (~< 5). Othervise StringBuilder is preferable. In the case I'd use var name = LanguagePrimitives.ConvertTo<String>(fieldName);
contentDisposition.Name = String.Create(2+name.Length, name, (Span<char> destination, string str) =>
{
destination[0] = '"';
str.AsSpan().CopyTo(destination.Slice(1));
destination[destination.Length-1] = '"';
}); |
Why? Why always use explicit culture? String concatenation does not require it. It is relvant when doing formatting or transformations, but just combining strings it's senseless.
If this will unblock this PR so it will be merged, I will change it to use
Why? That is a seriously over-complicated verbose and tough to follow piece code just to put |
We never know exactly what users will do. |
We do know that this is a form submission style that is not as widely adopted as standard forms. We do know that the intended purpose of this submission method is GUI browser based communications. We do know that some APIs do use this for file uploads, but not all. We do know that while there have been asks for this feature to be added, not many. If I didn't have my own personal need for it, it may never have even entered consideration to be adopted in the web cmdlets. Yes, we are not clairvoyant and we cannot know 100% what users will do, but, let's be realistic here: the string concatenation for quoting field names filename values and of this feature is NEVER going to be a performance concern. Especially when it is already associated with slow, long running, and memory intense tasks (uploading data). The few fractions of a millisecond shaved off and memory usage saved by using What I do know for certain is that I will have to look at this code in the future. And very likely, someone else will too. I do know that String.Create() is complex and not easy to read. I do know that I can skim the If you want to add a string concatenation utility method that allows us to abstract |
|
Forget about
This is not obviously for code reviewer. My first impression was that it evidently. Then there were questions. Why we use formatting if we need quoting? Why we use Summing up this discussion I think |
|
@rkeithhill What plugin you use in VS Code to see IL? |
|
It would be much appreciated if this PR makes it in for Preview3. Just sayin'. :-) |



PR Summary
-Formis used, the field names and the filename value will be enclosed in quotesSince
-Formhas not been released in an actual release version, this is not a breaking change.There is no decent way to test this as the metadata for text fields is lost when the form is processed in ASP.NET. Only way would be to return the raw request body and parse it with regex.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests