Skip to content

Commit f36312f

Browse files
committed
URI authority should start with word characters
1 parent 9f03eca commit f36312f

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

packages/core/src/__tests__/Uri.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,10 @@ describe("Uri", () => {
7878
expect(uri.authority).toEqual("authority");
7979
expect(uri.path).toEqual("something?uri=wrap://something/something2");
8080
});
81+
82+
it("Shouldn't accept authorities that don't start with alphanumeric characters", () => {
83+
expect(() => {
84+
new Uri("../invalid/path");
85+
}).toThrow(/URI authority must start with an alphanumeric character or an underscore\./);
86+
});
8187
});

packages/core/src/types/Uri.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ export class Uri {
175175

176176
// Extract the authority and path
177177
const authority = parts[0];
178+
179+
// Authority should begin with a word character (alphanumeric, underscore)
180+
const validAuthorityRegExp = /^\w.*/;
181+
if (!validAuthorityRegExp.test(authority)) {
182+
return ResultErr(
183+
Error(
184+
`URI authority must start with an alphanumeric character or an underscore.\n` +
185+
`Invalid URI Received: ${input}`
186+
)
187+
);
188+
}
189+
178190
const path = parts.slice(1).join("/");
179191

180192
if (!path) {

0 commit comments

Comments
 (0)