Skip to content

Commit

Permalink
Merge pull request #384 from baynezy/feature/issue-383-sonar
Browse files Browse the repository at this point in the history
Fix sonar recommendations
  • Loading branch information
baynezy authored Feb 12, 2024
2 parents 74ce16b + 7608850 commit fe20e50
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .idea/.idea.Html2Markdown/.idea/sonarlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/.idea.Html2Markdown/.idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/Html2Markdown/Replacement/HtmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,11 @@ private static string GetSyntaxHighlightLanguage(HtmlNode node)
return string.Empty;
}

return classAttributeValue.StartsWith("lang")
? classAttributeValue.Split('-').Last()
: classAttributeValue;
if (!classAttributeValue.StartsWith("lang")) return classAttributeValue;
var split = classAttributeValue.Split('-');

return split[^1]; // PERFORMANCE: https://sonarcloud.io/organizations/baynezy/rules?open=csharpsquid%3AS6608&rule_key=csharpsquid%3AS6608

}

internal static string ReplaceBlockquote(string html)
Expand Down
3 changes: 2 additions & 1 deletion src/Html2Markdown/Replacement/PatternReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class PatternReplacer : IReplacer
public string Replacement { get; init; }
public string Replace(string html)
{
var regex = new Regex(Pattern);
// SECURITY: https://sonarcloud.io/organizations/baynezy/rules?open=csharpsquid%3AS6444&rule_key=csharpsquid%3AS6444
var regex = new Regex(Pattern, RegexOptions.None, TimeSpan.FromSeconds(1));

return regex.Replace(html, Replacement);
}
Expand Down

0 comments on commit fe20e50

Please sign in to comment.