Skip to content

Conversation

@Divyanshu-Mishra9620
Copy link

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
Copy link
Author

@MichakrawSB Please can you review this pr

@glowcloud
Copy link
Contributor

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.

@Divyanshu-Mishra9620
Copy link
Author

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.

Copy link
Contributor

@glowcloud glowcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Divyanshu-Mishra9620
Copy link
Author

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.

Copy link
Contributor

@glowcloud glowcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Divyanshu-Mishra9620,

I requested some last changes:

  1. I tested the PR locally and the linting did not pass for the test file. Our style guide prefers using double quotes when possible and avoids semicolons - I left comments related to that.
  2. As mentioned before, we do not accept changes to any files in dist folder through PRs. Please remove any changes done there.


describe("escapeCMD", () => {
it("escapes vertical bar | with caret ^ for CMD", () => {
const input = 'foo|bar';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const input = 'foo|bar';
const input = "foo|bar"

describe("escapeCMD", () => {
it("escapes vertical bar | with caret ^ for CMD", () => {
const input = 'foo|bar';
const output = escapeCMD(input);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const output = escapeCMD(input);
const output = escapeCMD(input)

it("escapes vertical bar | with caret ^ for CMD", () => {
const input = 'foo|bar';
const output = escapeCMD(input);
expect(output).toContain('^|');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(output).toContain('^|');
expect(output).toContain("^|")

const input = 'foo|bar';
const output = escapeCMD(input);
expect(output).toContain('^|');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
})

});

it("escapes other CMD special characters", () => {
expect(escapeCMD('foo^bar')).toContain('^^');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(escapeCMD('foo^bar')).toContain('^^');
expect(escapeCMD("foo^bar")).toContain("^^")


it("escapes other CMD special characters", () => {
expect(escapeCMD('foo^bar')).toContain('^^');
expect(escapeCMD('foo"bar')).toContain('""');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(escapeCMD('foo"bar')).toContain('""');
expect(escapeCMD('foo"bar')).toContain('""')

it("escapes other CMD special characters", () => {
expect(escapeCMD('foo^bar')).toContain('^^');
expect(escapeCMD('foo"bar')).toContain('""');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
})

expect(escapeCMD('foo^bar')).toContain('^^');
expect(escapeCMD('foo"bar')).toContain('""');
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
})

- Add vertical bar (|) escaping in escapeCMD function
- Update test to use double quotes and no semicolons per project style guide
- Revert dev-helper-initializer.js to previous commented state

Fixes swagger-api#10540
- Remove all changes to dist/ folder as they are not accepted in PRs
- Remove unrelated changes to source files not part of the bug fix
- Keep only the vertical bar escaping fix and its test
@Divyanshu-Mishra9620
Copy link
Author

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

const regionId = createHtmlReadyId(`${method}${path}_responses`)
const controlId = `${regionId}_select`

return (!nonExtensionResponses || !nonExtensionResponses.size) ? null : (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the reason of removing this code ? is this related to the vertical bar character problem ?

@lukaszzazulak
Copy link
Contributor

@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.

@Divyanshu-Mishra9620
Copy link
Author

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants