Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splat not being passed as Query String #4273

Closed
hrishikesh-k opened this issue Feb 13, 2022 · 2 comments · Fixed by #4897
Closed

Splat not being passed as Query String #4273

hrishikesh-k opened this issue Feb 13, 2022 · 2 comments · Fixed by #4897
Assignees
Labels
area: functions area: redirects type: bug code to address defects in shipped code

Comments

@hrishikesh-k
Copy link

Describe the bug:

Using splat in sending query parameters to a destination doesn't seem to be working.

To reproduce:

Add the following to your netlify.toml:

[[redirects]]
  force = true
  from = "/foo/*"
  status = 301
  to = "/.netlify/functions/bar/?url=:splat"

Create a function with the following:

exports.handler = async ({queryStringParameters}) => {
  return {
    body: JSOSN.strigify(queryStringParameters),
    statusCode: 200
  }
}

The output returns empty.

Configuration

  System:
    OS: macOS 12.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.44 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.5 - ~/.nvm/versions/node/v14.17.5/bin/node
    npm: 6.14.14 - ~/.nvm/versions/node/v14.17.5/bin/npm
  npmPackages:
    netlify-cli: ^9.4.0 => 9.4.0

Expected behavior

The query string should have some value if the requested URL was /foo/bar/.

CLI Output

N/A

Additional context

N/A

@hrishikesh-k hrishikesh-k added type: bug code to address defects in shipped code area: functions area: redirects labels Feb 13, 2022
@jackiewmacharia
Copy link
Contributor

Observations so far: I'm seeing this bug on a local environment with netlify dev on v9.6.4 as well as a local clone of netlify/cli.

It however doesn't seem to be the case in production, testing using code in this repo. For example:

Currently investigating local env behavior.

@jackiewmacharia jackiewmacharia self-assigned this Mar 17, 2022
@tinfoil-knight
Copy link
Contributor

@jackiewmacharia It seems like this was done intentionally to match old production behaviour.

See #1605

Relevant code is here:

cli/src/utils/proxy.js

Lines 204 to 216 in 7b89caf

// We pass through request params in one of the following cases:
// 1. The redirect rule doesn't have any query params
// 2. This is a function redirect https://github.com/netlify/cli/issues/1605
if ([...dest.searchParams].length === 0 || isFunction(options.functionsPort, stripOrigin(dest))) {
dest.searchParams.forEach((_, key) => {
dest.searchParams.delete(key)
})
const requestParams = new URLSearchParams(reqUrl.searchParams)
requestParams.forEach((val, key) => {
dest.searchParams.append(key, val)
})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: functions area: redirects type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants