Skip to content
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
6 changes: 6 additions & 0 deletions app/api/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ describe('parsePortRange', () => {
expect(parsePortRange('1-45690')).toEqual([1, 45690])
expect(parsePortRange('5-5')).toEqual([5, 5])
})

it('with surrounding whitespace', () => {
expect(parsePortRange('123-456 ')).toEqual([123, 456])
expect(parsePortRange(' 1-45690')).toEqual([1, 45690])
expect(parsePortRange(' 5-5 \n')).toEqual([5, 5])
})
})

describe('rejects', () => {
Expand Down
2 changes: 1 addition & 1 deletion app/api/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type PortRange = [number, number]
// null so we can annotate the failure with a reason
export function parsePortRange(portRange: string): PortRange | null {
// TODO: pull pattern from openapi spec (requires generator work)
const match = /^([0-9]{1,5})((?:-)[0-9]{1,5})?$/.exec(portRange)
const match = /^([0-9]{1,5})((?:-)[0-9]{1,5})?$/.exec(portRange.trim())
if (!match) return null

const p1 = parseInt(match[1], 10)
Expand Down
Loading