-
Notifications
You must be signed in to change notification settings - Fork 94
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 false positives for 'SARIF1002.UrisMustBeValid' due to Uri.IsWellFormedUriString bug #2501
Conversation
…medUri, plus added example.
@@ -246,6 +246,18 @@ internal static string JsonPointerToJavaScript(string pointerString) | |||
return sb.ToString(); | |||
} | |||
|
|||
internal static bool UriIsWellFormedUriString(string uriString, UriKind uriKind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -246,6 +246,18 @@ internal static string JsonPointerToJavaScript(string pointerString) | |||
return sb.ToString(); | |||
} | |||
|
|||
internal static bool UriIsWellFormedUriString(string uriString, UriKind uriKind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest naming IsWellFormedUriString per C# style guidelines #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
src/ReleaseHistory.md
Outdated
@@ -3,6 +3,7 @@ | |||
## Unreleased | |||
|
|||
* FEATURE: Add `max-file-size-in-kb` argument that allows filtering scan targets by file size. [#2494](https://github.com/microsoft/sarif-sdk/pull/2494) | |||
* BUGFIX: Fix false positive for `SARIF1002.UrisMustBeValid` for URIs with the format `file:/c:/location/filename.txt`. [#]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -80,7 +80,7 @@ private void AnalyzeUri(Uri uri, string pointer) | |||
string uriString = uri?.OriginalString; | |||
if (uriString != null) | |||
{ | |||
if (!Uri.IsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute)) | |||
if (!UriIsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal static bool UriIsWellFormedUriString(string uriString, UriKind uriKind) | ||
{ | ||
bool isWellFormed = Uri.IsWellFormedUriString(uriString, uriKind); | ||
bool csBug = (uriString.StartsWith("file:/") && Uri.TryCreate(uriString, uriKind, out Uri result)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -80,7 +80,7 @@ private void AnalyzeUri(Uri uri, string pointer) | |||
string uriString = uri?.OriginalString; | |||
if (uriString != null) | |||
{ | |||
if (!Uri.IsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute)) | |||
if (!UriIsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute)) | |||
{ | |||
// {0}: The string '{1}' is not a valid URI reference. URIs must conform to | |||
// [RFC 3986](https://tools.ietf.org/html/rfc3986). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this information in the helper.
#Pending
internal static bool UriIsWellFormedUriString(string uriString, UriKind uriKind) | ||
{ | ||
bool isWellFormed = Uri.IsWellFormedUriString(uriString, uriKind); | ||
bool csBug = (uriString.StartsWith("file:/") && Uri.TryCreate(uriString, uriKind, out Uri result)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
expectedIsWellFormedUri = true, | ||
uriKind = UriKind.Absolute, | ||
uriString = "file:///c:/Code/sarif-sdk/src/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
expectedIsWellFormedUri = true, | ||
uriKind = UriKind.RelativeOrAbsolute, | ||
uriString = "file:///c:/Code/sarif-sdk/src/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/ReleaseHistory.md
Outdated
@@ -3,6 +3,7 @@ | |||
## Unreleased | |||
|
|||
* FEATURE: Add `max-file-size-in-kb` argument that allows filtering scan targets by file size. [#2494](https://github.com/microsoft/sarif-sdk/pull/2494) | |||
* BUGFIX: Fix false positive for `SARIF1002.UrisMustBeValid` for URIs with the format `file:/c:/location/filename.txt`. [#]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Test.UnitTests.Sarif.Multitool.Library/Rules/SARIF1002.UrisMustBeValidTests.cs
Fixed
Show fixed
Hide fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ning BuildAndTest
Uri.IsWellFormedUriString
returns false for some valid URIs. This is resulting in some tools rejecting valid SARIF results files that conform to requirements but not all recommendations.This fix implements a IsWellFormedUri method as part of the SarifValidationSkimmerBase class and replaces all
Uri.IsWellFormedUriString()
api calls with this method.