Skip to content

Commit 7a4d4e6

Browse files
committed
refactor: make Sanitize.SanitizeUserInput null-safe
Accept a nullable string and return string.Empty for null input rather than throwing NullReferenceException. This addresses the root cause of the test regression introduced when sanitizing missionTask.Id in AreaPolygonService and removes the need for an inline null check at the call site. All other callers pass values that are either guaranteed non-null by model binding ([Required] DTO properties) or already null-checked explicitly (UpdateRobotQuery), so the new behaviour is observationally equivalent for them while removing a sharp edge for future callers.
1 parent ab45a24 commit 7a4d4e6

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

backend/api/Services/AreaPolygonService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ public bool MissionTasksAreInsideAreaPolygon(
4545
robotPosition.X,
4646
robotPosition.Y,
4747
robotPosition.Z,
48-
missionTask.Id is null
49-
? string.Empty
50-
: Sanitize.SanitizeUserInput(missionTask.Id)
48+
Sanitize.SanitizeUserInput(missionTask.Id)
5149
);
5250
return false;
5351
}

backend/api/Utilities/SanitizeInput.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace Api.Utilities
55
{
66
public static class Sanitize
77
{
8-
public static string SanitizeUserInput(string inputString)
8+
public static string SanitizeUserInput(string? inputString)
99
{
10-
return inputString.Replace("\n", "").Replace("\r", "");
10+
return inputString?.Replace("\n", "").Replace("\r", "") ?? string.Empty;
1111
}
1212

1313
public static ScheduleMissionQuery SanitizeUserInput(ScheduleMissionQuery inputQuery)

0 commit comments

Comments
 (0)