-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fix String.Format
to handle formatting of multiple types correctly, not only DateTime
#31
Fix String.Format
to handle formatting of multiple types correctly, not only DateTime
#31
Conversation
"String.Format" used to only support "DateTime" for formatting. As for now, as soon as the value implements "IFormattable" that interface is used to perform the formatting. Also, if the format provider exposes a "ICustomFormatter" service, that formatter is used first for formatting the value. The formatting falls back to "ToString()" or to an empty string if the value to format is null.
If it's any help about the build failing, it seems that the task "Prepare analysis on SonarCloud" did not run because: "References service endpoint. PRs from repository forks are not allowed to access secrets in the pipeline. For more information see https://go.microsoft.com/fwlink/?linkid=862029" This then caused the "SonarCloud: Run Code Analysis" task to fail because it was not prepared ! |
@DamienBraillard . Thank you for the PR. I'll take a look. About the CI-build failing, I don't know/see the difference between this CI build and this CI build (https://github.com/WireMock-Net/WireMock.Net/blob/master/azure-pipelines-ci.yml) A PR on WireMock.Net does work correctly? |
About the CI failure: The step Prepare analysis on SonarCloud did not run, eventually causing the SonarCloud: Run Code Analysis step to fail. The following warning gives a hint at what is happening:
How is you See the Azure Pipelines documentation on Contributions from forks:
|
@0xced |
The secret variables was not the cause. Searching for "PRs from repository forks are not allowed to access secrets in the pipeline" lead me to the source code of the Azure Pipeline agent runner. And the key in this error message was this: Apparently, the task is skipped because you have configured service connection credentials. |
@0xced And for this project, this checkbox is not enabled. However, I think that enabling this checkbox is unsafe, like someone can see the secret MyGetKey ? |
Indeed, your secret MyGetKey could be retrieved by someone forking your repository if you make secrets available to builds of forks and you don't want that. Do you have a service connection configured? I think this could be the actual cause of the skipped task. The secret variables was just red herring. |
I think for now I'll approve + merge this PR. And update the pipeline yml to include |
Hi,
First, thanks for the hard work and the great library !
I started using Handlebars.Net and the associated Handlebars.Net.Helpers because I need to format values (which Stubble can't do easily). What I need to format is an "Instant" value representing a date from the "NodaTime" library.
I was quite surprised to get an error
The method Format cannot be used on value '2001-11-21T00:00:00Z' of Type 'NodaTime.Instant'
.Looking into the code, it seems that only DateTime is supported:
The method should make use of
ICustomFormatter
andIFormattable
to format values as these interfaces are intended for this purpose (this is what theString.Format
method uses to format string). Using these interfaces would allow formatting anything that can be like theString.Format
method does.Here is an example of a failing test that attempts to format a
Decimal
(But it is the same for NodaTimeInstant
):