Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Types for file paths and plain text #9624

Open
jrdodds opened this issue Jan 10, 2024 · 3 comments
Open

[Feature Request]: Types for file paths and plain text #9624

jrdodds opened this issue Jan 10, 2024 · 3 comments
Labels
backlog Feature Request gathering-feedback The issue requires feedback in order to be planned, please comment if the feature is useful for you Priority:3 Work that is nice to have triaged

Comments

@jrdodds
Copy link
Contributor

jrdodds commented Jan 10, 2024

Summary

In documentation/specs/proposed, security-metadata.md states:

We envision MSBuild to have a first-class-[citizen] type system for [its] data and tasks. 'Secret' would be one of the data types ...

If a type system is introduced, please include a file path type and a plain text type.

Background and Motivation

When a TaskItem is constructed (or ItemSpec is set), the value is passed through FileUtilities.FixFilePath:

public TaskItem(
string itemSpec)
{
ErrorUtilities.VerifyThrowArgumentNull(itemSpec, nameof(itemSpec));
_itemSpec = FileUtilities.FixFilePath(itemSpec);
}

public string ItemSpec
{
get => _itemSpec == null ? string.Empty : EscapingUtilities.UnescapeAll(_itemSpec);
set
{
ErrorUtilities.VerifyThrowArgumentNull(value, nameof(ItemSpec));
_itemSpec = FileUtilities.FixFilePath(value);
_fullPath = null;
}
}

internal static string FixFilePath(string path)
{
return string.IsNullOrEmpty(path) || Path.DirectorySeparatorChar == '\\' ? path : path.Replace('\\', '/'); // .Replace("//", "/");
}

FixFilePath makes no change under Windows (where Path.DirectorySeparatorChar will be '\\') but on *NIX OSs (macOS and Linux) a \ character will be replaced with a / character. This makes some sense for file paths but when an Item collection is used for data that is not file paths and that contains \ characters, the data is corrupted.

This issue shows up in multiple places and ways but one example is using the ReadLinesFromFile task to read a JavaScript file that has code using regular expressions. The \ character is an escape character in REs. The same MSBuild project will work correctly on Windows and corrupt the RE expressions on Linux and macOS.

Proposed Feature

  • Have a plain text type for values that should not be interpreted.
  • Have a file path type that supports making file paths portable/convertible.
    • Can be defined with a relative path in either a Windows style or a UNIX style and, when its value is accessed, it tries to default to the current platform.
    • It should be possible to explicitly get a UNIX style path under Windows and vice versa.
    • Converting fully qualified paths may not be supported.

Alternative Designs

No response

@jrdodds jrdodds added Feature Request needs-triage Have yet to determine what bucket this goes in. labels Jan 10, 2024
@jrdodds jrdodds changed the title [Feature Request]: Types for file paths and plain text to correctly handle *NIX paths [Feature Request]: Types for file paths and plain text Jan 10, 2024
@jrdodds
Copy link
Contributor Author

jrdodds commented Jan 10, 2024

See bugs #1622 and #3468.

@AR-May AR-May added backlog and removed needs-triage Have yet to determine what bucket this goes in. labels Jan 16, 2024
@JanKrivanek
Copy link
Member

FYI @baronfel

Thank you @jrdodds for a nice suggestion.
The strong type system is not yet on the top of MSBuild team priority list (though it's something that was discussed internaly couple times).

@JanKrivanek JanKrivanek added gathering-feedback The issue requires feedback in order to be planned, please comment if the feature is useful for you triaged labels Jan 16, 2024
@lonix1
Copy link

lonix1 commented Jan 16, 2024

SO question issue that started this issue.

@rokonec rokonec added the Priority:3 Work that is nice to have label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Feature Request gathering-feedback The issue requires feedback in order to be planned, please comment if the feature is useful for you Priority:3 Work that is nice to have triaged
Projects
None yet
Development

No branches or pull requests

5 participants