From e574975bd0d88b4c38d851bd96961515d43b1858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deniz=20G=C3=BCney=20Y=C4=B1ld=C4=B1r=C4=B1m?= Date: Tue, 1 Sep 2026 23:02:22 +0300 Subject: [PATCH 1/2] feat: add constructor validation checks to BasePolicy Closes #333852 --- build/lib/policies/basePolicy.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/build/lib/policies/basePolicy.ts b/build/lib/policies/basePolicy.ts index 7f650ba7b2edd3..3c12aa38934fe5 100644 --- a/build/lib/policies/basePolicy.ts +++ b/build/lib/policies/basePolicy.ts @@ -22,6 +22,25 @@ export abstract class BasePolicy implements Policy { description: NlsString, moduleName: string, ) { + if (!type) { + throw new Error("BasePolicy: 'type' parametresi zorunludur ve boş bırakılamaz."); + } + if (!name || typeof name !== 'string' || name.trim() === '') { + throw new Error("BasePolicy: Geçerli bir 'name' değeri gereklidir."); + } + if (!category) { + throw new Error("BasePolicy: 'category' parametresi zorunludur."); + } + if (!minimumVersion || typeof minimumVersion !== 'string' || !/^\d+(\.\d+)*$/.test(minimumVersion)) { + throw new Error(`BasePolicy: Geçersiz 'minimumVersion' formatı (${minimumVersion}). Sürüm numarası sayısal değerlerden oluşmalıdır (örn. '1.0.0').`); + } + if (!description || !description.nlsKey) { + throw new Error("BasePolicy: Geçerli bir 'description' ve 'nlsKey' gereklidir."); + } + if (!moduleName || typeof moduleName !== 'string' || moduleName.trim() === '') { + throw new Error("BasePolicy: Geçerli bir 'moduleName' değeri gereklidir."); + } + this.type = type; this.name = name; this.category = category; From 245c969871730004ec380c93735ec2e18c588c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deniz=20G=C3=BCney=20Y=C4=B1ld=C4=B1r=C4=B1m?= Date: Tue, 1 Sep 2026 23:12:53 +0300 Subject: [PATCH 2/2] fix: address copilot feedback on BasePolicy constructor validation Refine validation to support empty moduleName, enforce major.minor version format, use English error messages, and add structured type/category checks. --- build/lib/policies/basePolicy.ts | 33 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/build/lib/policies/basePolicy.ts b/build/lib/policies/basePolicy.ts index 3c12aa38934fe5..069168753d2752 100644 --- a/build/lib/policies/basePolicy.ts +++ b/build/lib/policies/basePolicy.ts @@ -22,23 +22,34 @@ export abstract class BasePolicy implements Policy { description: NlsString, moduleName: string, ) { - if (!type) { - throw new Error("BasePolicy: 'type' parametresi zorunludur ve boş bırakılamaz."); + // 1. PolicyType kontrolü + if (!type || typeof type !== 'string') { + throw new Error("BasePolicy: 'type' is required and must be a valid PolicyType."); } + + // 2. Name kontrolü if (!name || typeof name !== 'string' || name.trim() === '') { - throw new Error("BasePolicy: Geçerli bir 'name' değeri gereklidir."); + throw new Error("BasePolicy: A valid non-empty 'name' is required."); } - if (!category) { - throw new Error("BasePolicy: 'category' parametresi zorunludur."); + + // 3. Category yapı kontrolü (category.name ve nlsKey varlığı) + if (!category || typeof category !== 'object' || !category.name || typeof category.name.nlsKey !== 'string' || category.name.nlsKey.trim() === '') { + throw new Error("BasePolicy: A valid 'category' with a proper 'nlsKey' structure is required."); } - if (!minimumVersion || typeof minimumVersion !== 'string' || !/^\d+(\.\d+)*$/.test(minimumVersion)) { - throw new Error(`BasePolicy: Geçersiz 'minimumVersion' formatı (${minimumVersion}). Sürüm numarası sayısal değerlerden oluşmalıdır (örn. '1.0.0').`); + + // 4. İki bileşenli Major.Minor sürüm formatı kontrolü (örn. "1.0") + if (!minimumVersion || typeof minimumVersion !== 'string' || !/^\d+\.\d+$/.test(minimumVersion)) { + throw new Error(`BasePolicy: Invalid 'minimumVersion' format (${minimumVersion}). It must follow the major.minor convention (e.g., '1.0').`); } - if (!description || !description.nlsKey) { - throw new Error("BasePolicy: Geçerli bir 'description' ve 'nlsKey' gereklidir."); + + // 5. Description kontrolü + if (!description || typeof description !== 'object' || typeof description.nlsKey !== 'string' || description.nlsKey.trim() === '') { + throw new Error("BasePolicy: A valid 'description' object with a 'nlsKey' is required."); } - if (!moduleName || typeof moduleName !== 'string' || moduleName.trim() === '') { - throw new Error("BasePolicy: Geçerli bir 'moduleName' değeri gereklidir."); + + // 6. moduleName kontrolü (Fabrikaların boş string kullanımına izin veriyoruz, sadece tip kontrolü yapılıyor) + if (moduleName === undefined || moduleName === null || typeof moduleName !== 'string') { + throw new Error("BasePolicy: 'moduleName' must be a string."); } this.type = type;