Skip to content

Apply PR #1 URL normalization suggestions and accept schemeless URLs in FE validation#4

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/apply-suggestions-from-pr-1
Draft

Apply PR #1 URL normalization suggestions and accept schemeless URLs in FE validation#4
Copilot wants to merge 4 commits intomainfrom
copilot/apply-suggestions-from-pr-1

Conversation

Copy link
Contributor

Copilot AI commented Feb 14, 2026

This addresses the merged PR feedback on URL normalization edge cases and updates frontend validation so inputs without an explicit URI scheme are accepted. The flow now consistently normalizes user input before validation/storage while preserving HTTPS-only enforcement.

  • Backend normalization hardening (src/api/worker.ts)

    • Trim original_url before processing.
    • Return 400 with URL is required for empty/whitespace-only input.
    • Keep scheme-prefix behavior only when no URI scheme is present, avoiding malformed double-scheme URLs.
  • Frontend validation accepts schemeless input (src/client/lib/validation.ts)

    • Added normalizeUrlInput() to:
      • trim input
      • prepend https:// when scheme is missing
    • Applied normalization via z.preprocess(...) in urlSchema.
    • Kept HTTPS-only rule after normalization.
  • Paste flow aligned with validation (src/client/routes/index.tsx)

    • Paste handler now normalizes pasted text and submits it directly.
    • Removed manual rejection path that previously blocked schemeless URLs.
  • Example (normalization behavior)

    normalizeUrlInput(" example.com ")      // "https://example.com"
    normalizeUrlInput("HTTPS://example.com")// "HTTPS://example.com"
    normalizeUrlInput("http://example.com") // "http://example.com" (later rejected by HTTPS rule)
  • screenshot


💡 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.

Co-authored-by: arhen <15151850+arhen@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 14, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
url-shortener 31c7f25 Feb 14 2026, 03:02 PM

Copilot AI and others added 2 commits February 14, 2026 15:00
Co-authored-by: arhen <15151850+arhen@users.noreply.github.com>
Co-authored-by: arhen <15151850+arhen@users.noreply.github.com>
Copilot AI changed the title [WIP] Apply suggestions from merged PR to improve validation Apply PR #1 URL normalization suggestions and accept schemeless URLs in FE validation Feb 14, 2026
Copilot AI requested a review from arhen February 14, 2026 15:02
@arhen arhen requested a review from Copilot February 14, 2026 15:15
Copy link
Owner

@arhen arhen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances URL input handling by implementing consistent normalization across frontend and backend, allowing users to submit URLs without explicit schemes (e.g., "example.com") while maintaining HTTPS-only enforcement. The changes address edge cases from a previous PR and improve the user experience by accepting schemeless URLs and normalizing them transparently.

Changes:

  • Added normalizeUrlInput() function to trim input and prepend https:// when no URI scheme is present
  • Integrated normalization into frontend validation via Zod preprocessing while keeping HTTPS-only enforcement
  • Simplified paste handler to normalize all non-empty input and submit directly, removing manual error handling
  • Hardened backend to trim URLs, reject empty/whitespace-only input, and avoid double-scheme URLs

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/client/lib/validation.ts Added normalizeUrlInput function and integrated it into urlSchema via z.preprocess, maintains HTTPS-only validation
src/client/routes/index.tsx Simplified paste handler to use normalizeUrlInput and rely on schema validation, removed manual error path, reorganized imports
src/api/worker.ts Added URL trimming, empty string validation, and scheme-checking before normalization to prevent malformed URLs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants