DoozyX / clang-format-lint-action

This action checks if the source code matches the .clang-format file.
MIT License
129 stars 46 forks source link

Workflow Fails if Path provided in "Source" input contains whitespace #62

Closed rjwignar closed 6 months ago

rjwignar commented 7 months ago

Problem

Like a few others, I pair clang-format-lint with tj-actions/changed-files to pass a list of modified files to clang-format-lint. This pairing works great. However, I've noticed the workflow fails when a filepath contains whitespaces: image.

I've been able to trace this bug back to PR #14 which acknowledges the limitation

Details

In the screenshot provided above, the files argument:

"features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli src/Features/DistantTreeLighting.cpp src/Features/DistantTreeLighting.h"

Becomes split by split_list_arg() into:

'features/Complex',
'Parallax',
'Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli',
'features/Complex',
'Parallax',
'Materials/Shaders/ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli',
'src/Features/DistantTreeLighting.cpp src/Features/DistantTreeLighting.h'

Possible Solution

I believe this can be solved by extending split_list_arg() to properly parse directories containing whitespaces. If the whitespaces are escaped using backward slashes, e.g features/Complex\ Parallax\ Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli instead of

features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli

...then split_list_arg() can be extended to split the whole paths by whitespaces while preserving these filepaths.

I've already made modifications to run-clang-format.py that should achieve this. I'll have a PR ready in a bit.