Skip to content

refactor: consolidate duplicate validation logic between PropertyDefinition.Validate and Test-TypedValue #36

@HeyItsGilbert

Description

@HeyItsGilbert

Summary

Integer min/max and string length/pattern validation logic exists in two places with two different behavioral contracts:

  • PropertyDefinition.Validate() (Classes/Property.ps1:62) — writes Write-Warning, returns $false
  • Test-TypedValue (Private/Test-TypedValue.ps1) — via WithOutPropertyDefinition param set: throws exceptions

When Test-Condition calls Test-TypedValue via the WithPropertyDefinition set, it delegates back to Validate() and discards the return value. Three code paths, two behaviors, one answer dropped.

Files

  • Gatekeeper/Classes/Property.ps1:62-94
  • Gatekeeper/Private/Test-TypedValue.ps1
  • Gatekeeper/Public/Test-Condition.ps1:93

Recommended Approach

Decide on one canonical contract and route everything through it:

  1. PropertyDefinition.Validate($Value) becomes the single validation function, returns a result object (or throws, per the chosen contract)
  2. Test-TypedValue either delegates entirely to PropertyDefinition.Validate or is removed
  3. Test-Condition captures the result and fails the rule on validation failure (see Issue security: path traversal in FeatureFlagTransformAttribute and ConditionGroupTransformAttribute #18)

This is related to Issue #18 (validation result discarded) and should be addressed in the same PR.

Notes

  • Found by Sage Nakamura and Jordan B.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode quality, structure, or naming

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions