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 packages/core/src/__tests__/Uri.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ describe("Uri", () => {
expect(uri.authority).toEqual("authority");
expect(uri.path).toEqual("something?uri=wrap://something/something2");
});

it("Shouldn't accept authorities that don't start with alphanumeric characters", () => {
expect(() => {
new Uri("../invalid/path");
}).toThrow(/URI authority must start with an alphanumeric character or an underscore\./);
});
});
12 changes: 12 additions & 0 deletions packages/core/src/types/Uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ export class Uri {

// Extract the authority and path
const authority = parts[0];

// Authority should begin with a word character (alphanumeric, underscore)
const validAuthorityRegExp = /^\w.*/;
if (!validAuthorityRegExp.test(authority)) {
return ResultErr(
Error(
`URI authority must start with an alphanumeric character or an underscore.\n` +
`Invalid URI Received: ${input}`
)
);
}

const path = parts.slice(1).join("/");

if (!path) {
Expand Down