diff --git a/src/Sarif.Driver/Sdk/Skimmer.cs b/src/Sarif.Driver/Sdk/Skimmer.cs index 0e75e36c4..4cf7e791c 100644 --- a/src/Sarif.Driver/Sdk/Skimmer.cs +++ b/src/Sarif.Driver/Sdk/Skimmer.cs @@ -13,15 +13,16 @@ public Skimmer() { this.Options = new Dictionary(); } + private IDictionary multiformatMessageStrings; - virtual protected ResourceManager ResourceManager => null; + protected virtual ResourceManager ResourceManager => null; - virtual protected IEnumerable MessageResourceNames => throw new NotImplementedException(); + protected virtual IEnumerable MessageResourceNames => throw new NotImplementedException(); virtual public FailureLevel DefaultLevel { get { return FailureLevel.Warning; } } - override public IDictionary MessageStrings + public override IDictionary MessageStrings { get { @@ -43,38 +44,7 @@ private Dictionary InitializeMultiformatMessag public override MultiformatMessageString FullDescription => throw new InvalidOperationException($"The {nameof(FullDescription)} property must be overridden in the SkimmerBase-derived class."); - public override MultiformatMessageString ShortDescription - { - get { return new MultiformatMessageString { Text = FirstSentence(FullDescription.Text) }; } - } - - internal static string FirstSentence(string fullDescription) - { - int charCount = 0; - bool withinApostrophe = false; - - foreach (char ch in fullDescription) - { - charCount++; - switch (ch) - { - case '\'': - { - withinApostrophe = !withinApostrophe; - continue; - } - - case '.': - { - if (withinApostrophe) { continue; } - return fullDescription.Substring(0, charCount); - } - } - } - int length = Math.Min(fullDescription.Length, 80); - bool truncated = length < fullDescription.Length; - return fullDescription.Substring(0, length) + (truncated ? "..." : ""); - } + public override MultiformatMessageString ShortDescription => new MultiformatMessageString { Text = ExtensionMethods.GetFirstSentence(FullDescription.Text) }; public override string Name => this.GetType().Name; diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1001.DoNotUseFriendlyNameAsRuleId_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1001.DoNotUseFriendlyNameAsRuleId_Invalid.sarif index facfa1d9c..b206144a8 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1001.DoNotUseFriendlyNameAsRuleId_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1001.DoNotUseFriendlyNameAsRuleId_Invalid.sarif @@ -11,7 +11,7 @@ "id": "SARIF1001", "name": "DoNotUseFriendlyNameAsRuleId", "shortDescription": { - "text": "Do not use the same string for a rule's id and name properties. The id property ..." + "text": "Do not use the same string for a rule's id and name properties." }, "fullDescription": { "text": "Do not use the same string for a rule's id and name properties. The id property must be a stable, opaque identifer such as \"SARIF1001\". The name property should be a string that is understandable to an end user, such as \"DoNotUserFriendlyNameAsRuleId\"." diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif index c3917ab09..82e99fb1e 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif @@ -11,7 +11,7 @@ "id": "SARIF1018", "name": "InvalidUriInOriginalUriBaseIds", "shortDescription": { - "text": "In the artifactLocation objects contained in run." + "text": "In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent." }, "fullDescription": { "text": "In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent. Also, uri must end with a slash, so that it can safely be combined with the relative URIs in artifactLocation objects elsewhere in the log file." diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1019.RuleIdMustBePresentAndConsistent_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1019.RuleIdMustBePresentAndConsistent_Invalid.sarif index b30399062..75862b94f 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1019.RuleIdMustBePresentAndConsistent_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1019.RuleIdMustBePresentAndConsistent_Invalid.sarif @@ -11,7 +11,7 @@ "id": "SARIF1019", "name": "RuleIdMustBePresentAndConsistent", "shortDescription": { - "text": "In every result, at least one of the properties result." + "text": "In every result, at least one of the properties result.ruleId and result.rule.id must be present." }, "fullDescription": { "text": "In every result, at least one of the properties result.ruleId and result.rule.id must be present. If both are present, they must be equal." diff --git a/src/Test.UnitTests.Sarif/ExtensionsTests.cs b/src/Test.UnitTests.Sarif/ExtensionsTests.cs index 71213102b..b5b1ae437 100644 --- a/src/Test.UnitTests.Sarif/ExtensionsTests.cs +++ b/src/Test.UnitTests.Sarif/ExtensionsTests.cs @@ -401,6 +401,7 @@ public void Extensions_ConsumeElementOfDepth_ConsumesEndElement() [InlineData("Abbreviations such as approx. don't fool us.", "Abbreviations such as approx. don't fool us.")] // Expected bad output cases [InlineData("no space after period.cannot return good sentence.", "no space after period.cannot return good sentence.")] + [InlineData("In every result, at least one of the properties result.ruleId and result.rule.id must be present. If both are present, they must be equal.", "In every result, at least one of the properties result.ruleId and result.rule.id must be present.")] public void Extensions_ExtractsFirstSentenceProperly(string input, string expected) { string actual = ExtensionMethods.GetFirstSentence(input);