File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( / U R I a u t h o r i t y m u s t s t a r t w i t h a n a l p h a n u m e r i c c h a r a c t e r o r a n u n d e r s c o r e \. / ) ;
86+ } ) ;
8187} ) ;
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments