Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.7.1 — 2026-07-25

- Reject trailing newlines in validated values: anchor regexes with `\z`
instead of `$` in `CounterExample::toExamplesCode()` (the examples-method
name passed to the reflection/replay path) and in `PropertyInterceptor` /
`SeedStorage` integer parsers. The latter two are hygiene only — env values
and `trim()`'ed seed-file contents already strip the newline before the
regex runs.

## 2.7.0 — 2026-07-25

- Ship an AI agent skill (`resources/skills/rasuvaeff-property-testing/SKILL.md` +
Expand Down
2 changes: 1 addition & 1 deletion src/CounterExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function toJson(bool $pretty = false): string

public function toExamplesCode(string $methodName = 'propertyExamples'): string
{
if (preg_match('/^[A-Za-z_]\w*$/', $methodName) !== 1) {
if (preg_match('/^[A-Za-z_]\w*\z/', $methodName) !== 1) {
throw new \InvalidArgumentException(sprintf('Invalid examples method name "%s"', $methodName));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Internal/PropertyInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private function resolveRuns(int $runs): int
return $runs;
}

if (preg_match('/^\d+$/', $env) !== 1 || (int) $env < 1) {
if (preg_match('/^\d+\z/', $env) !== 1 || (int) $env < 1) {
throw new \InvalidArgumentException(sprintf('PROPERTY_RUNS must be a positive integer, got "%s"', $env));
}

Expand Down Expand Up @@ -478,7 +478,7 @@ private function resolveSeed(?int $attributeSeed): int
return random_int(0, PHP_INT_MAX);
}

if (preg_match('/^-?\d+$/', $env) !== 1) {
if (preg_match('/^-?\d+\z/', $env) !== 1) {
throw new \InvalidArgumentException(sprintf('PROPERTY_SEED must be an integer, got "%s"', $env));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/SeedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function recall(string $id): ?int

$content = file_get_contents($file);

if ($content === false || preg_match('/^-?\d+$/', trim($content)) !== 1) {
if ($content === false || preg_match('/^-?\d+\z/', trim($content)) !== 1) {
return null;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/CounterExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public function rejectsInvalidExamplesMethodName(): void
(new CounterExample(1, 0, [], []))->toExamplesCode('not-valid');
}

#[ExpectException(\InvalidArgumentException::class)]
public function rejectsExamplesMethodNameWithTrailingNewline(): void
{
(new CounterExample(1, 0, [], []))->toExamplesCode("validName\n");
}

#[ExpectException(\LogicException::class)]
public function refusesToGenerateNonRunnableObjectExampleCode(): void
{
Expand Down
Loading