{"action":"created","comment":{"url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/comments/45768246","id":45768246,"diff_hunk":"@@ -0,0 +1,107 @@\n+﻿//-----------------------------------------------------------------------\n+// <copyright file=\"SarifUtilities.cs\" company=\"SonarSource SA and Microsoft Corporation\">\n+//   Copyright (c) SonarSource SA and Microsoft Corporation.  All rights reserved.\n+//   Licensed under the MIT License. See License.txt in the project root for license information.\n+// </copyright>\n+//-----------------------------------------------------------------------\n+\n+using System;\n+using System.Collections.Generic;\n+using System.Linq;\n+using System.Text;\n+using Newtonsoft.Json;\n+using Newtonsoft.Json.Linq;\n+using System.Diagnostics;\n+\n+namespace SonarQube.Common\n+{\n+    public static class RoslynV1SarifFixer\n+    {\n+        /// <summary>\n+        /// Returns true if the given SARIF came from the VS 2015 RTM Roslyn, which does not provide correct output.\n+        /// </summary>\n+        public /* for test */ static bool IsSarifFromRoslynV1(string input)\n+        {\n+            // low risk of false positives / false negatives\n+            return (input.Contains(@\"\"\"toolName\"\": \"\"Microsoft (R) Visual C# Compiler\"\"\")\n+                && input.Contains(@\"\"\"productVersion\"\": \"\"1.0.0\"\"\"));\n+        }\n+\n+        /// <summary>\n+        /// Used to correct invalid SARIF generated by VS 2015 RTM Roslyn. \n+        /// Correctly escapes backslashes and quotes.\n+        /// \n+        /// Returns true if the output is valid SARIF (even if there was no change).\n+        /// \n+        /// Example invalid line:\n+        /// \"shortMessage\": \"message \\test\\ [\"_\"]\",\n+        /// \n+        /// Example valid line:\n+        /// \"shortMessage\": \"message \\\\test\\\\ [\\\"_\\\"]\",\n+        /// </summary>\n+        public /* for test */ static bool FixRoslynV1Sarif(string input, out string output)\n+        {\n+            try {\n+                JObject.Parse(input);\n+\n+                output = input; // no change necessary if input was valid\n+                return true; \n+            } catch (JsonReaderException) // we expect invalid JSON\n+            {\n+                if (!IsSarifFromRoslynV1(input))\n+                {\n+                    // invalid SARIF that has not originated from VS 2015 RTM cannot be fixed\n+                    output = input;\n+                    return false;\n+                } else \n+                {\n+                    string[] inputLines = input.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);","path":"SonarQube.Common/RoslynV1SarifFixer.cs","position":58,"original_position":58,"commit_id":"bc113fad8b198057a44f6c863c3889a1f78c0d1a","original_commit_id":"bc113fad8b198057a44f6c863c3889a1f78c0d1a","user":{"login":"duncanpMS","id":10757559,"avatar_url":"https://avatars.githubusercontent.com/u/10757559?v=3","gravatar_id":"","url":"https://api.github.com/users/duncanpMS","html_url":"https://github.com/duncanpMS","followers_url":"https://api.github.com/users/duncanpMS/followers","following_url":"https://api.github.com/users/duncanpMS/following{/other_user}","gists_url":"https://api.github.com/users/duncanpMS/gists{/gist_id}","starred_url":"https://api.github.com/users/duncanpMS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duncanpMS/subscriptions","organizations_url":"https://api.github.com/users/duncanpMS/orgs","repos_url":"https://api.github.com/users/duncanpMS/repos","events_url":"https://api.github.com/users/duncanpMS/events{/privacy}","received_events_url":"https://api.github.com/users/duncanpMS/received_events","type":"User","site_admin":false},"body":"As SonarLint says, the cyclomatic complexity is too high. Split out the \"fix\" logic into a separate method. That will leave this method with the outer control flow logic, and a helper method that handles the low-level fix up.","created_at":"2015-11-24T17:37:59Z","updated_at":"2015-11-24T17:37:59Z","html_url":"https://github.com/SonarSource/sonar-msbuild-runner/pull/150#discussion_r45768246","pull_request_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/150","_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/comments/45768246"},"html":{"href":"https://github.com/SonarSource/sonar-msbuild-runner/pull/150#discussion_r45768246"},"pull_request":{"href":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/150"}}},"pull_request":{"url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/150","id":51648571,"html_url":"https://github.com/SonarSource/sonar-msbuild-runner/pull/150","diff_url":"https://github.com/SonarSource/sonar-msbuild-runner/pull/150.diff","patch_url":"https://github.com/SonarSource/sonar-msbuild-runner/pull/150.patch","issue_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/issues/150","number":150,"state":"open","locked":false,"title":"[SONARMSBRU-177] Fix capability for invalid SARIF from RTM Roslyn.","user":{"login":"HSAR","id":985911,"avatar_url":"https://avatars.githubusercontent.com/u/985911?v=3","gravatar_id":"","url":"https://api.github.com/users/HSAR","html_url":"https://github.com/HSAR","followers_url":"https://api.github.com/users/HSAR/followers","following_url":"https://api.github.com/users/HSAR/following{/other_user}","gists_url":"https://api.github.com/users/HSAR/gists{/gist_id}","starred_url":"https://api.github.com/users/HSAR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HSAR/subscriptions","organizations_url":"https://api.github.com/users/HSAR/orgs","repos_url":"https://api.github.com/users/HSAR/repos","events_url":"https://api.github.com/users/HSAR/events{/privacy}","received_events_url":"https://api.github.com/users/HSAR/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-24T11:39:35Z","updated_at":"2015-11-24T17:37:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dfd4b7b4773e943dc5ae4b795fde41964442180c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/150/commits","review_comments_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/150/comments","review_comment_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/issues/150/comments","statuses_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/statuses/bc113fad8b198057a44f6c863c3889a1f78c0d1a","head":{"label":"HSAR:master","ref":"master","sha":"bc113fad8b198057a44f6c863c3889a1f78c0d1a","user":{"login":"HSAR","id":985911,"avatar_url":"https://avatars.githubusercontent.com/u/985911?v=3","gravatar_id":"","url":"https://api.github.com/users/HSAR","html_url":"https://github.com/HSAR","followers_url":"https://api.github.com/users/HSAR/followers","following_url":"https://api.github.com/users/HSAR/following{/other_user}","gists_url":"https://api.github.com/users/HSAR/gists{/gist_id}","starred_url":"https://api.github.com/users/HSAR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HSAR/subscriptions","organizations_url":"https://api.github.com/users/HSAR/orgs","repos_url":"https://api.github.com/users/HSAR/repos","events_url":"https://api.github.com/users/HSAR/events{/privacy}","received_events_url":"https://api.github.com/users/HSAR/received_events","type":"User","site_admin":false},"repo":{"id":46124465,"name":"sonar-msbuild-runner","full_name":"HSAR/sonar-msbuild-runner","owner":{"login":"HSAR","id":985911,"avatar_url":"https://avatars.githubusercontent.com/u/985911?v=3","gravatar_id":"","url":"https://api.github.com/users/HSAR","html_url":"https://github.com/HSAR","followers_url":"https://api.github.com/users/HSAR/followers","following_url":"https://api.github.com/users/HSAR/following{/other_user}","gists_url":"https://api.github.com/users/HSAR/gists{/gist_id}","starred_url":"https://api.github.com/users/HSAR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HSAR/subscriptions","organizations_url":"https://api.github.com/users/HSAR/orgs","repos_url":"https://api.github.com/users/HSAR/repos","events_url":"https://api.github.com/users/HSAR/events{/privacy}","received_events_url":"https://api.github.com/users/HSAR/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HSAR/sonar-msbuild-runner","description":"","fork":true,"url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner","forks_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/forks","keys_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/teams","hooks_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/hooks","issue_events_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/issues/events{/number}","events_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/events","assignees_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/assignees{/user}","branches_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/branches{/branch}","tags_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/tags","blobs_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/git/refs{/sha}","trees_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/statuses/{sha}","languages_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/languages","stargazers_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/stargazers","contributors_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/contributors","subscribers_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/subscribers","subscription_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/subscription","commits_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/commits{/sha}","git_commits_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/git/commits{/sha}","comments_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/comments{/number}","issue_comment_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/issues/comments{/number}","contents_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/contents/{+path}","compare_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/merges","archive_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/downloads","issues_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/issues{/number}","pulls_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/pulls{/number}","milestones_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/milestones{/number}","notifications_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/labels{/name}","releases_url":"https://api.github.com/repos/HSAR/sonar-msbuild-runner/releases{/id}","created_at":"2015-11-13T13:48:17Z","updated_at":"2015-11-13T13:48:19Z","pushed_at":"2015-11-24T17:10:22Z","git_url":"git://github.com/HSAR/sonar-msbuild-runner.git","ssh_url":"git@github.com:HSAR/sonar-msbuild-runner.git","clone_url":"https://github.com/HSAR/sonar-msbuild-runner.git","svn_url":"https://github.com/HSAR/sonar-msbuild-runner","homepage":null,"size":2887,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SonarSource:master","ref":"master","sha":"0b808d7663019cf02c3e1ec507c0671496052413","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":34444711,"name":"sonar-msbuild-runner","full_name":"SonarSource/sonar-msbuild-runner","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonar-msbuild-runner","description":"","fork":false,"url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner","forks_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/forks","keys_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/events","assignees_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/merges","archive_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/releases{/id}","created_at":"2015-04-23T08:45:40Z","updated_at":"2015-11-18T07:58:58Z","pushed_at":"2015-11-24T17:10:49Z","git_url":"git://github.com/SonarSource/sonar-msbuild-runner.git","ssh_url":"git@github.com:SonarSource/sonar-msbuild-runner.git","clone_url":"https://github.com/SonarSource/sonar-msbuild-runner.git","svn_url":"https://github.com/SonarSource/sonar-msbuild-runner","homepage":null,"size":2998,"stargazers_count":23,"watchers_count":23,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":5,"forks":22,"open_issues":5,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/150"},"html":{"href":"https://github.com/SonarSource/sonar-msbuild-runner/pull/150"},"issue":{"href":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/issues/150"},"comments":{"href":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/issues/150/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/150/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/pulls/150/commits"},"statuses":{"href":"https://api.github.com/repos/SonarSource/sonar-msbuild-runner/statuses/bc113fad8b198057a44f6c863c3889a1f78c0d1a"}}}}