Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow passing numbers as path template parameters #756

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pathTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface Segment {
}

export interface Bindings {
[index: string]: string;
[index: string]: string | number;
}

export class PathTemplate {
Expand Down Expand Up @@ -129,7 +129,7 @@ export class PathTemplate {
);
throw new TypeError(msg);
}
const tmp = new PathTemplate(bindings[segment.literal]);
const tmp = new PathTemplate(bindings[segment.literal].toString());
Array.prototype.push.apply(out, tmp.segments);
inABinding = true;
} else if (segment.kind === extras.END_BINDING) {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/path_template.ts → test/unit/pathTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ describe('PathTemplate', () => {
const want = 'bar/1/2/foo/3';
expect(template.render(params)).to.eql(want);
});

it('should accept both strings and numbers as values', () => {
const template = new PathTemplate(
'projects/{project}/sessions/{session}'
);
const params = {
project: 'testProject',
session: 123,
};
const want = 'projects/testProject/sessions/123';
expect(template.render(params)).to.eql(want);
});
});

describe('method `inspect`', () => {
Expand Down