Skip to content

Commit

Permalink
Update coding example
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Dec 9, 2024
1 parent d1ee5fd commit 2ececbd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 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 @@ -142,6 +141,14 @@ public ActionResult Post()
var cultureName = Request.QueryString["locale"] ?? "en-US"; // Noncompliant: Request.QueryString
// ..
}
public IActionResult Post()
{
var origin = Request.Headers[HeaderNames.Origin]; // Compliant: Access via variable
var name = Request.Form["name"]; // Compliant: Access via constant and variable keys is mixed
var birthdate = DateTime.Parse(Request.Form["Birthdate"]); // Compliant: Access via constant and variable keys is mixed
// ..
}
----

==== Compliant solution
Expand Down

0 comments on commit 2ececbd

Please sign in to comment.