@@ -9,18 +9,20 @@ const { ERR_VALIDATION } = require("./error_codes.cjs");
99 * @returns {string[] }
1010 */
1111function parseAllowedIssueFields ( value ) {
12- if ( value == null || value === "" ) {
13- return [ ] ;
14- }
12+ if ( value == null || value === "" ) return [ ] ;
1513 const raw = Array . isArray ( value ) ? value : String ( value ) . split ( "," ) ;
16- const uniqueFields = new Set ( ) ;
17- for ( const item of raw ) {
18- const normalized = String ( item ) . trim ( ) ;
19- if ( normalized ) {
20- uniqueFields . add ( normalized ) ;
21- }
22- }
23- return [ ...uniqueFields ] ;
14+ return [ ...new Set ( raw . map ( item => String ( item ) . trim ( ) ) . filter ( Boolean ) ) ] ;
15+ }
16+
17+ /**
18+ * Build a lowercased Set from allowedFields.
19+ * Returns null when no restriction applies (empty list, non-array, or wildcard "*").
20+ * @param {string[] } allowedFields
21+ * @returns {Set<string>|null }
22+ */
23+ function buildAllowedFieldSet ( allowedFields ) {
24+ if ( ! Array . isArray ( allowedFields ) || allowedFields . length === 0 || allowedFields . includes ( "*" ) ) return null ;
25+ return new Set ( allowedFields . map ( f => f . toLowerCase ( ) ) ) ;
2426}
2527
2628/**
@@ -30,14 +32,10 @@ function parseAllowedIssueFields(value) {
3032 * @returns {void }
3133 */
3234function validateAllowedIssueFieldName ( fieldName , allowedFields ) {
33- if ( ! fieldName ) {
34- return ;
35- }
36- if ( ! Array . isArray ( allowedFields ) || allowedFields . length === 0 || allowedFields . includes ( "*" ) ) {
37- return ;
38- }
39- const allowedFieldSet = new Set ( allowedFields . map ( field => field . toLowerCase ( ) ) ) ;
40- if ( ! allowedFieldSet . has ( fieldName . toLowerCase ( ) ) ) {
35+ if ( ! fieldName ) return ;
36+ const fieldSet = buildAllowedFieldSet ( allowedFields ) ;
37+ if ( ! fieldSet ) return ;
38+ if ( ! fieldSet . has ( fieldName . toLowerCase ( ) ) ) {
4139 throw new Error ( `${ ERR_VALIDATION } : issue field "${ fieldName } " is not in the allowed-fields list: ${ allowedFields . join ( ", " ) } ` ) ;
4240 }
4341}
@@ -49,18 +47,11 @@ function validateAllowedIssueFieldName(fieldName, allowedFields) {
4947 * @returns {void }
5048 */
5149function validateAllowedIssueFields ( issueFields , allowedFields ) {
52- if ( ! Array . isArray ( issueFields ) || issueFields . length === 0 ) {
53- return ;
54- }
55- if ( ! Array . isArray ( allowedFields ) || allowedFields . length === 0 ) {
56- return ;
57- }
58- const allowedFieldSet = new Set ( allowedFields . map ( field => field . toLowerCase ( ) ) ) ;
59- if ( allowedFieldSet . has ( "*" ) ) {
60- return ;
61- }
50+ if ( ! Array . isArray ( issueFields ) || issueFields . length === 0 ) return ;
51+ const fieldSet = buildAllowedFieldSet ( allowedFields ) ;
52+ if ( ! fieldSet ) return ;
6253 for ( const field of issueFields ) {
63- if ( ! allowedFieldSet . has ( field . name . toLowerCase ( ) ) ) {
54+ if ( ! fieldSet . has ( field . name . toLowerCase ( ) ) ) {
6455 throw new Error ( `${ ERR_VALIDATION } : issue field "${ field . name } " is not in the allowed-fields list: ${ allowedFields . join ( ", " ) } ` ) ;
6556 }
6657 }
0 commit comments