Skip to content

Commit

Permalink
Quote the full URL in cURL commands (#5566)
Browse files Browse the repository at this point in the history
Motivation:

When copying a request as a cURL command in DocService, only the URL
path is quoted. For example, `curl http://localhost:8080'/foo/bar'`. It
would be better to quote the full URL, like `curl
'http://localhost:8080/foo/bar'`.

Modifications:

- Add quotes and call `escapeSingleQuote()` only when constructing the
final URL

Result:

- The copied cURL command has the full URL quoted

Tested the following outputs:

- `curl [...] 'http://localhost:8080/foo/bar'`
- `curl [...] 'http://localhost:8080/foo/bar?qwe=asd'`
- `curl [...] 'http://localhost:8080/foo/bar?qwe="asd"'`
- `curl [...] 'http://localhost:8080/foo/bar?qwe='\''asd'\'''`
  • Loading branch information
KarboniteKream authored May 7, 2024
1 parent 7d562ce commit b84e3f0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions docs-client/src/containers/MethodPage/DebugPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,29 +278,28 @@ const DebugPage: React.FunctionComponent<Props> = ({
serviceType === ServiceType.HTTP ||
serviceType === ServiceType.GRAPHQL
) {
const queries = additionalQueries;
const queries =
additionalQueries.length > 0 ? `?${additionalQueries}` : '';

if (exactPathMapping) {
endpoint = transport.getDebugMimeTypeEndpoint(method);
mappedPath =
`'${escapeSingleQuote(
endpoint.pathMapping.substring('exact:'.length),
)}` +
`${queries.length > 0 ? `?${escapeSingleQuote(queries)}` : ''}'`;
endpoint.pathMapping.substring('exact:'.length) + queries;
} else {
endpoint = transport.getDebugMimeTypeEndpoint(method, additionalPath);
mappedPath =
`'${escapeSingleQuote(additionalPath)}` +
`${queries.length > 0 ? `?${escapeSingleQuote(queries)}` : ''}'`;
mappedPath = additionalPath + queries;
}
} else if (additionalPath.length > 0) {
endpoint = transport.getDebugMimeTypeEndpoint(method, additionalPath);
mappedPath = `'${escapeSingleQuote(additionalPath)}'`;
mappedPath = additionalPath;
} else {
endpoint = transport.getDebugMimeTypeEndpoint(method);
mappedPath = `'${escapeSingleQuote(endpoint.pathMapping)}'`;
mappedPath = endpoint.pathMapping;
}

const uri = host + parseServerRootPath(docServiceRoute) + mappedPath;
const uri = `'${escapeSingleQuote(
host + parseServerRootPath(docServiceRoute) + mappedPath,
)}'`;

const body = transport.getCurlBody(
endpoint,
Expand Down

0 comments on commit b84e3f0

Please sign in to comment.