swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Fixes #10540 — Vertical bar character | not escaped in cURL (CMD) request snippet body

Open Divyanshu-Mishra9620 opened this issue 3 months ago • 7 comments

Problem

When generating cURL (CMD) request snippets, the vertical bar character | in the request body was not escaped. In Windows CMD, this causes the string after | to be interpreted as a command, resulting in errors.

Solution

Updated the CMD snippet generator to escape | as ^| in the request body. Enabled request snippets in the dev environment for easier testing.

Testing

Verified that the generated cURL (CMD) snippet now escapes | as ^|. Confirmed that pasting the snippet in Windows CMD no longer causes command parsing errors.

Before

swagger swagger2

After the change=> .replace(/|/g, "^|")

Screenshot 2025-10-08 182518 Screenshot 2025-10-08 182436

Divyanshu-Mishra9620 avatar Oct 08 '25 13:10 Divyanshu-Mishra9620

@MichakrawSB Please can you review this pr

Divyanshu-Mishra9620 avatar Oct 08 '25 16:10 Divyanshu-Mishra9620

Hi @Divyanshu-Mishra9620,

Thanks for this fix! The fix itself seems fine to me, but could you please remove changes unrelated to the issue? Also, could you provide a test for your fix? It should be located under test/unit/core/plugins/request-snippets/fn.js.

glowcloud avatar Oct 09 '25 07:10 glowcloud

Hi @Divyanshu-Mishra9620,

Thanks for this fix! The fix itself seems fine to me, but could you please remove changes unrelated to the issue? Also, could you provide a test for your fix? It should be located under test/unit/core/plugins/request-snippets/fn.js.

Title: Fix: Escape vertical bar (|) in cURL (CMD) request snippet body (#10540)

Description:

Escapes the vertical bar character | in cURL (CMD) request snippets with a caret ^ for Windows CMD compatibility. Adds a unit test for escapeCMD in fn.js to verify the fix.

Removes unrelated changes and unnecessary files from the PR.

These .LICENSE.txt files in the dist folder are automatically generated by Webpack when building the project.

Testing:

All tests pass, including the new unit test for CMD snippet escaping.

Divyanshu-Mishra9620 avatar Oct 09 '25 15:10 Divyanshu-Mishra9620

Thanks for the tests! I left a few comments requesting some changes.

As for the changes to files in the dist folder - they are updated only during the release process, as can be seen in the commit history here.

Hey @glowcloud made the changes as suggested.

Divyanshu-Mishra9620 avatar Oct 11 '25 12:10 Divyanshu-Mishra9620

@glowcloud Hey i have fixed, if the issue still exist i will work on that.

Divyanshu-Mishra9620 avatar Oct 14 '25 09:10 Divyanshu-Mishra9620

@glowcloud Hey i have fixed, if the issue still exist i will work on that.

@Divyanshu-Mishra9620 It look like there are still changes unrelated to the bug, have a look at my comment for example.

lukaszzazulak avatar Oct 18 '25 09:10 lukaszzazulak

This PR fixes issue #10540 by ensuring the vertical bar (|) character is properly escaped in CMD request snippets.

  • In an earlier commit, I mistakenly changed unrelated logic in the Responses component (removing the nonExtensionResponses filter). This was not related to the vertical bar bug and was an oversight. I have now reverted those changes, and this PR only contains the intended bug fix and its related test.

Divyanshu-Mishra9620 avatar Oct 18 '25 18:10 Divyanshu-Mishra9620