netlify / netlify/cli

Redirect doesn't work if there's a leading space in the address

Open
#4,707 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue type: bug
Dominant language
TypeScript
Stars
1.9k
Forks
474
Avg merge
23h 30m
Merged PRs (30d)
53

Description

Describe the bug

if I have a leading space in a redirect, the redirect doesn't work.

This was obviously an issue caused by user error but I unexpectedly lost a lot of time on this cursed space. I believe this would be a quick win to resolve these typos issues by trimming the URI as they are known to not match the URI spec. If there is more nuance here than I am unaware of (most likely), then we should be able to trim reliably if the redirect trimmed redirect starts with ^http[s]?:\/\/

Steps to reproduce

Use a leading space in the to field of a redirect.

[[redirects]]
  from = "/test"
  to = " https://www.netlify.com"
  status = 200
Configuration

see steps to repro

Environment
System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 3.74 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.1 - /opt/homebrew/opt/nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.17 - /opt/homebrew/opt/nvm/versions/node/v16.13.1/bin/yarn
    npm: 8.1.2 - /opt/homebrew/opt/nvm/versions/node/v16.13.1/bin/npm
  npmGlobalPackages:
    netlify-cli: 10.3.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue in the netlify CLI with the redirect configuration shown, then locate the code that parses and handles redirect to values. Confirm how leading whitespace is treated and add coverage for this case. Done means the example redirect works as expected without changing valid redirect behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.