Skip to content

Commit f4c33df

Browse files
committed
Fix URI template multi-variable matching
1 parent 16d13ab commit f4c33df

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

packages/core/src/shared/uriTemplate.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ export class UriTemplate {
227227

228228
switch (part.operator) {
229229
case '': {
230+
if (part.names.length > 1) {
231+
return part.names.map((name, index) => ({
232+
pattern: `${index === 0 ? '' : ','}([^/,]+)`,
233+
name
234+
}));
235+
}
230236
pattern = part.exploded ? '([^/,]+(?:,[^/,]+)*)' : '([^/,]+)';
231237
break;
232238
}

packages/core/test/shared/uriTemplate.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ describe('UriTemplate', () => {
9898
expect(match).toEqual({ username: 'fred', postId: '123' });
9999
});
100100

101+
it('should match multiple variables in a simple expression', () => {
102+
const template = new UriTemplate('/users/{userId,format}');
103+
const match = template.match('/users/42,json');
104+
expect(match).toEqual({ userId: '42', format: 'json' });
105+
});
106+
101107
it('should return null for non-matching URIs', () => {
102108
const template = new UriTemplate('/users/{username}');
103109
const match = template.match('/posts/123');

0 commit comments

Comments
 (0)