Skip to content

handle edge cases in the name query parameter #5

@nofarblue

Description

@nofarblue

📝 Description
The current app (CreateGreeting and the HTTP handler) does not handle edge cases in the name query parameter. This can result in:

Unhelpful or inconsistent logs when name is empty, whitespace-only, or malformed
Potential for log injection or hard-to-read logs due to special characters (e.g., newlines)
Poor UX when names contain only whitespace or very long strings
We want to harden the input handling to make the app safer and the logs cleaner.

✅ Acceptance Criteria

Input validation (in CreateGreeting):

Trim leading/trailing whitespace

Return "Hello, Guest" if input is empty after trim

Limit accepted name length to 100 characters

Optionally strip or escape newline/control characters
Logging safety (in HTTP handler):

Escape or sanitize name before logging (e.g., remove newline/control chars)
Test coverage:

Name is empty → "Hello, Guest"

Name is only whitespace → "Hello, Guest"

Name includes newline or control characters

Name with special symbols (e.g., Jane!@#)

Very long name (>100 characters) → name should be truncated or rejected
🧪 Sample Unit Test Cases to Add

func TestGreeting_WhitespaceOnly(t *testing.T) { ... }
func TestGreeting_LongName(t *testing.T) { ... }
func TestGreeting_NewlineInjection(t *testing.T) { ... }
🧩 Notes
This is a minimal, self-contained enhancement ideal for evaluating Copilot’s issue assignment capabilities. It:

Involves logic + test changes
Doesn’t require any external APIs
Keeps scope limited but realistic
Touches areas where Copilot should excel (sanitization, string ops, tests)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions