From 17c1a3abe71a089c3eba4f773b572633e8f6ab0e Mon Sep 17 00:00:00 2001 From: Sebastien Marichal Date: Thu, 17 Aug 2023 14:43:16 +0200 Subject: [PATCH] Add FN repro for #7815 --- .../TestCases/UriShouldNotBeHardcoded.cs | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UriShouldNotBeHardcoded.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UriShouldNotBeHardcoded.cs index ab51595b5fb..bec8c15bb16 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UriShouldNotBeHardcoded.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UriShouldNotBeHardcoded.cs @@ -46,7 +46,6 @@ void InvalidCases(string s1, string s2) var webChemin = "http://www.mywebsite.com"; // FN var windowsChemin = "c:\\blah\\blah\\blah.txt"; // FN - // The rule only checks the string literals that are [arguments in methods/constructors] or [assignment] bool ReturnStement(string uri) { @@ -74,3 +73,35 @@ void ValidCases(string s) } } } + +// https://github.com/SonarSource/sonar-dotnet/issues/7815 +class ReproFN_7815 +{ + class MyClass + { + public string FilePath { get; set; } + } + + void Method() + { + var myClass = new MyClass + { + FilePath = "/my/other/folder" // Compliant - we ignore unix paths by default + }; + + var myClass2 = new MyClass + { + FilePath = @"\\my-network-drive\folder\file.txt" // FN + }; + + var myClass3 = new MyClass + { + FilePath = "http://www.mywebsite.com" // FN + }; + + var myClass4 = new MyClass + { + FilePath = "c:\\blah\\blah\\blah.txt" // FN + }; + } +}