-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support Intellij Multiline FormUrlEncoded Syntax (#699)
- Loading branch information
Showing
7 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { encodeRequestBody } from './encodeRequestBody'; | ||
import { Request } from '../../../models'; | ||
describe('encodeRequestBody', () => { | ||
it('encodeRequestBody should return encoded string', () => { | ||
const request = { | ||
body: 'a b', | ||
contentType: { | ||
mimeType: 'application/x-www-form-urlencoded', | ||
}, | ||
} as Request; | ||
encodeRequestBody(request); | ||
expect(request.body).toBe('a%20b'); | ||
}); | ||
it('encodeRequestBody should not transform if not valid mimeType', () => { | ||
const request = { | ||
body: 'a b', | ||
} as Request; | ||
encodeRequestBody(request); | ||
expect(request.body).toBe('a b'); | ||
}); | ||
it('encodeRequestBody should not transform if is buffer', () => { | ||
const request = { | ||
body: Buffer.from('a b'), | ||
} as Request; | ||
encodeRequestBody(request); | ||
expect(request.body).toBeInstanceOf(Buffer); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/plugins/core/request/transfromMultilineFormUrlEncoded.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { transfromMultilineFormUrlEncoded } from './transfromMultilineFormUrlEncoded'; | ||
import { Request } from '../../../models'; | ||
describe('transfromMultilineFormUrlEncoded', () => { | ||
it('transfromMultilineFormUrlEncoded should return joined string', () => { | ||
const request = { | ||
body: 'foo = a&\nbar = b', | ||
contentType: { | ||
mimeType: 'application/x-www-form-urlencoded', | ||
}, | ||
} as Request; | ||
transfromMultilineFormUrlEncoded(request); | ||
expect(request.body).toBe('foo=a&bar=b'); | ||
}); | ||
it('transfromMultilineFormUrlEncoded should ignore content on wrong mimetype', () => { | ||
const request = { | ||
body: 'foo = a&\nbar = b', | ||
} as Request; | ||
transfromMultilineFormUrlEncoded(request); | ||
expect(request.body).toBe('foo = a&\nbar = b'); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
src/plugins/core/request/transfromMultilineFormUrlEncoded.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as models from '../../../models'; | ||
import * as utils from '../../../utils'; | ||
|
||
export async function transfromMultilineFormUrlEncoded(request: models.Request): Promise<void> { | ||
if (request.body && utils.isString(request.body) && utils.isMimeTypeFormUrlEncoded(request.contentType)) { | ||
const lines = utils.toMultiLineArray(request.body); | ||
if (lines.length > 0) { | ||
const result = []; | ||
|
||
for (const line of lines) { | ||
result.push( | ||
line | ||
.split('=') | ||
.map(t => t.trim()) | ||
.join('=') | ||
); | ||
} | ||
request.body = result.join(''); | ||
} | ||
} | ||
} |