@@ -7,6 +7,8 @@ const inFile = core.getInput('in-file');
7
7
const inDirectory = core . getInput ( 'in-directory' ) ;
8
8
const outFile = core . getInput ( 'out-file' ) ;
9
9
10
+ const nameRegex = / ^ [ a - z A - Z ] ( [ _ a - z A - Z 0 - 9 ] ? [ a - z A - Z 0 - 9 ] ) * $ /
11
+
10
12
try
11
13
{
12
14
core . info ( "inFile: " + inFile ) ;
22
24
{
23
25
const fileData = fs . readFileSync ( inFile , 'utf8' ) ;
24
26
outputJson = JSON . parse ( fileData ) ;
27
+
28
+ // Validate object names
29
+ let anyFailed = false ;
30
+ Object . keys ( outputJson ) . forEach ( key =>
31
+ {
32
+ if ( ! nameRegex . test ( key ) )
33
+ {
34
+ core . error ( `Object name ${ key } from ${ inFile } is not a valid object name` ) ;
35
+ anyFailed = true ;
36
+ }
37
+ } ) ;
38
+ if ( anyFailed )
39
+ return ;
25
40
}
26
41
else
27
42
core . error ( "inDirectory " + inDirectory + " does not exist" ) ;
36
51
if ( ! filename . endsWith ( ".json" ) )
37
52
return ;
38
53
39
- const filenameWithoutExtension = filename . substring ( 0 , filename . length - ".json" . length ) ;
40
- if ( ! outputJson . hasOwnProperty ( filenameWithoutExtension ) ) {
41
- core . error ( filenameWithoutExtension + " is already defined (in " + inFile + ")" ) ;
54
+ const objectName = filename . substring ( 0 , filename . length - ".json" . length ) ;
55
+
56
+ // Validate name usability
57
+ if ( ! nameRegex . test ( objectName ) )
58
+ {
59
+ core . error ( objectName + " is invalid name for an object" ) ;
60
+ return ;
61
+ }
62
+
63
+ // Check for duplicates
64
+ if ( ! outputJson . hasOwnProperty ( objectName ) )
65
+ {
66
+ core . error ( objectName + " is already defined (in " + inFile + ")" ) ;
42
67
return ;
43
68
}
44
69
45
70
const fileData = fs . readFileSync ( inDirectory + '/' + filename , { encoding : 'utf8' , flag : 'r' } ) ;
46
- outputJson [ filenameWithoutExtension ] = JSON . parse ( fileData ) ;
71
+ outputJson [ objectName ] = JSON . parse ( fileData ) ;
47
72
} ) ;
48
73
}
49
74
else
62
87
{ encoding : 'utf8' , flag : 'w' }
63
88
) ;
64
89
}
65
-
66
90
}
67
91
catch ( error )
68
92
{
0 commit comments