File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ function scrub(data: any) {
3838 return data as FeatureData ;
3939}
4040
41+ const identifierPattern = / ^ [ a - z 0 - 9 - ] * $ / ;
42+
4143function * yamlEntries ( root : string ) : Generator < [ string , any ] > {
4244 const filePaths = new fdir ( )
4345 . withBasePath ( )
@@ -48,9 +50,13 @@ function* yamlEntries(root: string): Generator<[string, any]> {
4850 for ( const fp of filePaths ) {
4951 // The feature identifier/key is the filename without extension.
5052 const { name : key } = path . parse ( fp ) ;
51- const distPath = `${ fp } .dist` ;
53+
54+ if ( ! identifierPattern . test ( key ) ) {
55+ throw new Error ( `${ key } is not a valid identifier (must be lowercase a-z, 0-9, and hyphens)` ) ;
56+ }
5257
5358 const data = YAML . parse ( fs . readFileSync ( fp , { encoding : 'utf-8' } ) ) ;
59+ const distPath = `${ fp } .dist` ;
5460 if ( fs . existsSync ( distPath ) ) {
5561 const dist = YAML . parse ( fs . readFileSync ( distPath , { encoding : 'utf-8' } ) ) ;
5662 Object . assign ( data , dist ) ;
You can’t perform that action at this time.
0 commit comments