Skip to content

curl commands containing spaces won't execute in Linux terminals #4263

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

Open
dotasek opened this issue Feb 27, 2018 · 7 comments
Open

curl commands containing spaces won't execute in Linux terminals #4263

dotasek opened this issue Feb 27, 2018 · 7 comments

Comments

@dotasek
Copy link

dotasek commented Feb 27, 2018

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 2.0
Which Swagger-UI version? 3.11.0
How did you install Swagger-UI? Used dist directory for own version, verified on SwaggerUI demo
Which browser & version? 64.0.3282.167
Which operating system? Ubuntu 16.04 LTS

Expected Behavior

The generated curl available in the UI should be immediately executable when it's copied to a terminal, even if the address contains spaces.

Current Behavior

On operations that contain spaces, the generated curl cannot be executed within a linux console.

For example, this operation: POST /v1/commands/apps/list disabled results in a 400 error if you try to execute the resulting curl:

curl -X POST "http://localhost:1234/v1/commands/apps/list disabled" -H "accept: application/json"

Possible Solution

Replacing the spaces with %20 fixes the issue:

curl -X POST "http://localhost:1234/v1/commands/apps/list%20disabled" -H "accept: application/json"

Context

We are representing some underlying API that unfortunately allows spaces in its naming convention. Developers attempting to quickly script REST communications were held up.

@webron
Copy link
Contributor

webron commented Feb 27, 2018

Thanks for the report, but it would really help having an API definition that reproduces the problem.

@heldersepu
Copy link
Contributor

Here is a definition reproducing the issue:
petstore.swagger.io/?...url=http://heldersepu.github.io/hs-scripts/swagger/4263_swagger.yaml

I thing the Possible solution will be on:
https://github.com/swagger-api/swagger-ui/blob/master/src/core/curlify.js#L9
But is replacing spaces with %20 all we need? or are there other problematic characters?

@dotasek
Copy link
Author

dotasek commented Feb 28, 2018

Thank you Helder, that's the situation I was describing.

@heldersepu
Copy link
Contributor

heldersepu commented Feb 28, 2018

I was looking at other chars that could be causing problems the # is a problem too...
http://swagger-net-test.azurewebsites.net/swagger/ui/index?filter=ArrayTest#/ArrayTest/ArrayTest_Put
And that one is causing bigger problems in the UI

@vikramvi
Copy link

@dotasek can you please clarify

Replacing the spaces with %20 fixes the issue:

what's %20 mean ?

@ghost
Copy link

ghost commented Nov 19, 2018

@jzakrzewski
Copy link

curl expects that the URL is properly URL-encoded. The https://tools.ietf.org/html/rfc3986#section-2 explains what has to be encoded.
@vikramvi "%20" is simply an ASCII code for space written in hexadecimal.

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

No branches or pull requests

5 participants