Skip to content

Commit 5de67f8

Browse files
author
SkyFi Geek
committed
add unit test, apparently \\ is only required for one element with commas
1 parent de28182 commit 5de67f8

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

codegens/routeros-fetch/lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ function convert (request, options, callback) {
138138
if (header.includes('%') || header.includes(',')) {
139139
errors.push(`* Special characters in headers have many interpretations, check escaping - ${header} `);
140140
}
141-
if (header.includes(',')) {
142-
header = header.replace(/[,]/g, '\\,');
143-
}
144141
return utils.escapeRouterOSString(header);
145142
});
146143
if (headers.length === 1) {
144+
if (headers[0].includes(',')) {
145+
headers[0] = headers[0].replace(/[,]/g, '\\\\,');
146+
}
147147
attrs.set('http-header-field', headers[0]);
148148
}
149149
else if (headers.length > 1) {

codegens/routeros-fetch/test/unit/converter.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('Converter test', function () {
9191
);
9292
});
9393

94-
it('should escape commas in headers', function () {
94+
it('should escape commas in one header', function () {
9595
var request = new Request({
9696
method: 'GET',
9797
header: [
@@ -120,6 +120,41 @@ describe('Converter test', function () {
120120
);
121121
});
122122

123+
it('should NOT escape commas in one header', function () {
124+
var request = new Request({
125+
method: 'GET',
126+
header: [
127+
{
128+
key: 'Commas',
129+
value: 'a,1,2'
130+
},
131+
{
132+
key: 'More',
133+
value: 'x,y,z'
134+
135+
}
136+
],
137+
url: {
138+
raw: 'https://postman-echo.com/get',
139+
protocol: 'https',
140+
host: ['postman-echo', 'com'],
141+
path: ['get']
142+
}
143+
});
144+
convert(
145+
request,
146+
{ style: 'plain', commentary: 'none' },
147+
function (error, snippet) {
148+
if (error) {
149+
expect.fail(null, null, error);
150+
}
151+
console.log(snippet);
152+
expect(snippet).to.contain('a,1,2');
153+
expect(snippet).to.contain('x,y,z');
154+
}
155+
);
156+
});
157+
123158
it('should generate snippets(not error out) for requests with no body', function () {
124159
var request = new Request({
125160
method: 'GET',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postman-code-generators",
3-
"version": "1.13.1",
3+
"version": "1.13.2",
44
"description": "Generates code snippets for a postman collection",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)