Skip to content

Commit cea50de

Browse files
adjenksshockey
authored andcommitted
fix: pad with 0 when percent-encoding characters (via #1386)
* Fix lack of leading zero on low unicode values * linter fixes * logic fix * more logic fixes * drop unnecessary parens * add necessary paren * add tests
1 parent f754988 commit cea50de

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/execute/oas3/style-serializer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function encodeDisallowedCharacters(str, {escape} = {}, parse) {
3333
}
3434

3535
const encoded = (toUTF8Bytes(char) || [])
36-
.map(byte => byte.toString(16).toUpperCase())
36+
.map(byte => `0${byte.toString(16).toUpperCase()}`.slice(-2))
3737
.map(encodedByte => `%${encodedByte}`)
3838
.join('')
3939

test/oas3/execute/style-serializer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('OAS3 style serializer', () => {
2626
expect(tested('[')).toEqual('%5B')
2727
expect(tested(']')).toEqual('%5D')
2828
expect(tested('%')).toEqual('%25')
29+
expect(tested('\n')).toEqual('%0A')
2930
})
3031

3132
test('should correctly encode non-ASCII characters', () => {
@@ -58,6 +59,7 @@ describe('OAS3 style serializer', () => {
5859
expect(tested('@')).toEqual('@')
5960
expect(tested('[')).toEqual('[')
6061
expect(tested(']')).toEqual(']')
62+
expect(tested('\n')).toEqual('\n')
6163

6264
// Non-ASCII too!
6365
expect(tested('♥')).toEqual('♥')

0 commit comments

Comments
 (0)