Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 20, 2025

  • Analyze current codebase and understand the issue requirements
  • Verify current code builds and tests pass
  • Add comprehensive test cases for edge cases (whitespace, long names, control characters, special symbols)
  • Update CreateGreeting function to handle input validation (trim, length limit, sanitization)
  • Update HTTP handler to sanitize name parameter before logging
  • Verify all tests pass and edge cases are handled correctly
  • Test the running server to ensure proper behavior

Implemented comprehensive edge case handling for the name query parameter:

Input validation in CreateGreeting:

  • Trims leading/trailing whitespace using strings.TrimSpace()
  • Returns "Hello, Guest" if input is empty after trim
  • Limits accepted name length to 100 characters (truncates longer names)
  • Strips newline and control characters (ASCII 0-31, 127) and replaces with spaces

Logging safety in HTTP handler:

  • Sanitizes name parameter before logging to prevent log injection
  • Removes control characters that could break log formatting

Test coverage added:

  • TestGreeting_WhitespaceOnly: handles spaces, tabs, newlines, mixed whitespace
  • TestGreeting_LongName: truncates names longer than 100 characters
  • TestGreeting_NewlineInjection: sanitizes control characters in names
  • TestGreeting_SpecialSymbols: preserves valid special characters and Unicode
  • TestGreeting_TrimWhitespace: properly trims various whitespace combinations

All existing tests continue to pass, ensuring backward compatibility.

Fixes #5.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

handle edge cases in the name query parameter

2 participants