Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit b6ffe6e

Browse files
klokanekylef
authored andcommitted
fix(oas3): redefine path name allowed chars
1 parent 72e714a commit b6ffe6e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/fury-adapter-oas3-parser/lib/parser/oas/parseParameterObject.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ const isSupportedIn = R.anyPass([
3030

3131
const unreservedCharacterRegex = /^[A-z0-9\\.\\_\\~\\-]+$/;
3232
const reservedHeaderNamesRegex = /Accept|Content-Type|Authorization/i;
33+
const pathNameAllowedRegex = /^[A-z0-9._]+$/;
3334

3435
const encodeQueryName = name => encodeURIComponent(name)
3536
.replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16).toUpperCase()}`) // as sugested by https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#Description
3637
.replace(/%25([0-9a-f]{2})/gi, (match, hex) => `%${hex}`); // revert double encoded sequences
3738

38-
3939
function nameContainsReservedCharacter(parameter) {
4040
return !unreservedCharacterRegex.test(parameter.get('name').toValue());
4141
}
@@ -114,7 +114,13 @@ function parseParameterObject(context, object) {
114114

115115
const hasLocation = R.curry((location, parameter) => parameter.getValue('in') === location);
116116

117-
const validatePathName = R.when(nameContainsReservedCharacter, createUnsupportedNameError);
117+
const validatePathName = R.when(
118+
R.pipe(R.invoker(1, 'get')('name'),
119+
R.invoker(0, 'toValue'),
120+
R.test(pathNameAllowedRegex),
121+
R.not),
122+
createUnsupportedNameError
123+
);
118124

119125
const nameContainsReservedHeaderName = parameter => parameter.get('name')
120126
.toValue()

packages/fury-adapter-oas3-parser/test/unit/parser/oas/parseParameterObject-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ describe('Parameter Object', () => {
4444
expect(parseResult).to.contain.error("'Parameter Object' 'name' contains unsupported characters. Only alphanumeric characters are currently supported");
4545
});
4646

47+
it('does not allow character `-` in path name', () => {
48+
const parameter = new namespace.elements.Object({
49+
name: 'not-allowed',
50+
in: 'path',
51+
});
52+
53+
const parseResult = parse(context, parameter);
54+
55+
expect(parseResult).to.contain.error("'Parameter Object' 'name' contains unsupported characters. Only alphanumeric characters are currently supported");
56+
});
57+
4758
it('allows name to contain unreserved URI Template characters', () => {
4859
// as per https://tools.ietf.org/html/rfc6570#section-1.5
4960
const alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

0 commit comments

Comments
 (0)