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

URI authority should start with word characters #61

Merged
merged 1 commit into from
Jul 19, 2023
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
Loading