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

Replace special chars in InformationalVersion with dashes #2014

Merged
merged 9 commits into from Jan 6, 2020

Conversation

Skoucail
Copy link
Contributor

@Skoucail Skoucail commented Jan 3, 2020

Replacing all characters not allowed in SemVer 2.0 by dashes in the InformationVersion field.
This was already the case for the default format but not if a custom format was used.

2 tests were added to check the fix: one with and one without a format.

Discussion in #1520

src/GitVersionCore.Tests/VariableProviderTests.cs Outdated Show resolved Hide resolved
src/GitVersionCore.Tests/VariableProviderTests.cs Outdated Show resolved Hide resolved
src/GitVersionCore/OutputVariables/VariableProvider.cs Outdated Show resolved Hide resolved
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

I think this looks great, I just have one comment on the placement of the RegexReplace I'd like to discuss.

@@ -56,7 +57,7 @@ public VersionVariables GetVariablesFor(SemanticVersion semanticVersion, Effecti
var semverFormatValues = new SemanticVersionFormatValues(semanticVersion, config);

var informationalVersion = CheckAndFormatString(config.AssemblyInformationalFormat, semverFormatValues,
environment, semverFormatValues.DefaultInformationalVersion, "AssemblyInformationalVersion");
environment, semverFormatValues.DefaultInformationalVersion, "AssemblyInformationalVersion").RegexReplace("[^0-9A-Za-z-.+]", "-");
Copy link
Member

Choose a reason for hiding this comment

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

Is it not possible for CheckAndFormatString to perform the RegexReplace? The problem can in theory occur for assemblyFileSemVer and assemblySemVer as well if their formats or schemes include the prerelease label (tag)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm.
I see someone removed the fields assembly-versioning-format and assembly-file-versioning-format from the documentation but not from the code.

I would say it not needed to move the regex because for assembly version and assembly file version the rules are way more restricting.
Basicly only the schemes described in

MajorMinorPatchTag,
MajorMinorPatch,
MajorMinor,
Major,
None

and
MajorMinorPatchTag,
MajorMinorPatch,
MajorMinor,
Major,
None

are allowed by Microsoft specs.

I guess that is also the reason why the fields are no longer in the documentation for GitVersion 4.x and 5.x.

Also see Microsoft docs

Copy link
Member

Choose a reason for hiding this comment

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

Good point. Would moving the RegexReplace hurt, though? I would prefer it inside the method if it doesn't actually destroy anything.

Copy link
Contributor Author

@Skoucail Skoucail Jan 3, 2020

Choose a reason for hiding this comment

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

Nop would not hurt i guess.
Just a theoretical performance hit. But i don't think that will be noticeable.

Edit: actually the performance would be better as the RegexReplace will only be executed if a format has been given. I committed the change

@Skoucail Skoucail requested a review from asbjornu January 3, 2020 14:31
@asbjornu asbjornu merged commit b1bc4bc into GitTools:master Jan 6, 2020
@asbjornu
Copy link
Member

asbjornu commented Jan 6, 2020

Thank you so much for your contributions, @Skoucail! 🙏

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.

None yet

4 participants