Skip to content

Normalize temp dir in Given a directory step#329

Draft
swissspidy wants to merge 2 commits intomainfrom
fix/realpath
Draft

Normalize temp dir in Given a directory step#329
swissspidy wants to merge 2 commits intomainfrom
fix/realpath

Conversation

@swissspidy
Copy link
Copy Markdown
Member

No description provided.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Context/GivenStepDefinitions.php 0.00% 3 Missing ⚠️
src/Context/FeatureContext.php 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the temporary directory handling in GivenStepDefinitions.php to resolve macOS path normalization issues by incorporating realpath() and stripping the /private/var/ prefix. The review feedback recommends extending the path normalization to include /private/tmp/ to ensure consistency and refactoring the directory assignment logic for better readability.

$dir = Path::normalize( $dir );

// Also normalize temp dir for Mac OS X.
$temp_dir = preg_replace( '|^/private/var/|', '/var/', $temp_dir );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

On macOS, /tmp is also a symbolic link to /private/tmp. Since realpath() is now used, it might return /private/tmp if the system temp directory is set to /tmp (or if TMPDIR is set to /tmp). To avoid potential regressions in the security check on line 64, the regex should also handle the /private/tmp/ prefix, similar to how it handles /private/var/.

		$temp_dir = preg_replace( '|^/private/(var|tmp)/|', '/$1/', $temp_dir );

Comment on lines +56 to +57
$temp_dir = realpath( sys_get_temp_dir() );
$temp_dir = $temp_dir ? Path::normalize( $temp_dir ) : Path::normalize( sys_get_temp_dir() );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The assignment of $temp_dir can be simplified by using the Elvis operator and calling Path::normalize() once, which improves readability and slightly reduces redundancy.

		$temp_dir = Path::normalize( realpath( sys_get_temp_dir() ) ?: sys_get_temp_dir() );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant