Skip to content
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

Modify rule S6932: Update code example #4563

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion rules/S6932/csharp/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public IActionResult Post()
var name = Request.Form["name"]; // Noncompliant: Request.Form
var birthdate = DateTime.Parse(Request.Form["Birthdate"]); // Noncompliant: Request.Form

var origin = Request.Headers[HeaderNames.Origin]; // Noncompliant: Request.Headers
var locale = Request.Query.TryGetValue("locale", out var locales)
? locales.ToString()
: "en-US"; // Noncompliant: Request.Query
Expand Down Expand Up @@ -163,6 +162,17 @@ public ActionResult Post(User user, [Bind(Prefix = "locale")] string cultureName
// ...
}
}

public IActionResult Post()
{
var origin = Request.Headers[HeaderNames.Origin]; // Compliant: Access via non-constant field
var nameField = "name";
var name = Request.Form[nameField]; // Compliant: Access via local
var birthdate = DateTime.Parse(Request.Form["Birthdate"]); // Compliant: Access via constant and variable keys is mixed.
// Model binding would only work partially in the method, so we do not raise here.
return Ok();
// ..
}
----

include::../how-does-this-work.adoc[]
Expand Down
Loading