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

ensure that TryParse is used for all user input in editorconfig #17097

Conversation

jmarolf
Copy link
Contributor

@jmarolf jmarolf commented Feb 11, 2017

We got several reports in RC of Parse(int) throwing exceptions. This PR changes the editorconfig parsing of options to only use TryParse. It also simplifies several cases where we were passing a parsing function unnecessarily.

@jmarolf
Copy link
Contributor Author

jmarolf commented Feb 13, 2017

@dotnet/roslyn-ide please review

@agocke agocke changed the base branch from post-dev15 to master February 14, 2017 23:23
@Pilchie Pilchie added this to the 2.1 milestone Feb 22, 2017
@@ -27,6 +27,10 @@ public bool TryParseReadonlyDictionary(IReadOnlyDictionary<string, object> allRa
if (allRawConventions.TryGetValue(KeyName, out object value))
{
result = _parseValue(value.ToString(), type);
if (result == null)
Copy link
Member

Choose a reason for hiding this comment

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

return result != null;

@@ -49,11 +53,19 @@ public EditorConfigStorageLocation(string keyName)
{
if (type == typeof(int))
{
return int.Parse(s);
if (int.TryParse(s, out var value))
Copy link
Member

Choose a reason for hiding this comment

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

return int.TryParse(...) ? value : null;

{
return value;
}
return null;
Copy link
Member

Choose a reason for hiding this comment

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

what does null mean for an int? should this be 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

null means we couldn't parse it so return the default value.


In reply to: 102832529 [](ancestors = 102832529)

{
return value;
}
return null;
Copy link
Member

Choose a reason for hiding this comment

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

should this be false? or does 'null' just mean 'use the default'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

null in this case means use the default value.


In reply to: 102832596 [](ancestors = 102832596)

@jmarolf jmarolf force-pushed the bugfix/do-not-throw-exceptions-on-bad-editorconfig-files branch from 0702356 to f68b04c Compare February 23, 2017 22:50
@jmarolf
Copy link
Contributor Author

jmarolf commented Feb 23, 2017

retest windows_release_unit64_prtest please

@@ -12,79 +12,79 @@ internal static class CSharpCodeStyleOptions
public static readonly Option<CodeStyleOption<bool>> UseImplicitTypeForIntrinsicTypes = new Option<CodeStyleOption<bool>>(
nameof(CodeStyleOptions), nameof(UseImplicitTypeForIntrinsicTypes), defaultValue: CodeStyleOption<bool>.Default,
storageLocations: new OptionStorageLocation[] {
new EditorConfigStorageLocation("csharp_style_var_for_built_in_types", ParseEditorConfigCodeStyleOption),
new EditorConfigStorageLocation("csharp_style_var_for_built_in_types"),
Copy link
Member

Choose a reason for hiding this comment

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

Move ParseEditorConfigCodeStyleOption closer to EditorConfigStorageLocation.

Also consider caching the delegate for the parse function used in the 1-arg version of the EditorConfigStorageLocation constructor

@jmarolf jmarolf merged commit d935107 into dotnet:master Feb 24, 2017
@jmarolf jmarolf deleted the bugfix/do-not-throw-exceptions-on-bad-editorconfig-files branch January 27, 2020 16:57
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.

4 participants