From 53adcb0ae343cc09c2ef6ee9251706ff2c6d4697 Mon Sep 17 00:00:00 2001 From: Andrei Ignat Date: Mon, 21 Oct 2024 13:43:57 +0300 Subject: [PATCH] nameinjs --- .../Templates/NamePerCountDisplay.cshtml | 7 +++---- .../Templates/NamePerCountDisplayThreshold.cshtml | 6 +++--- src/NetPackageAnalyzer/NetPackageAnalyzerObjects/many.cs | 7 +++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/NetPackageAnalyzer/NetPackageAnalyzerExportHTML/Templates/NamePerCountDisplay.cshtml b/src/NetPackageAnalyzer/NetPackageAnalyzerExportHTML/Templates/NamePerCountDisplay.cshtml index 7fa6c0c..6dd5386 100644 --- a/src/NetPackageAnalyzer/NetPackageAnalyzerExportHTML/Templates/NamePerCountDisplay.cshtml +++ b/src/NetPackageAnalyzer/NetPackageAnalyzerExportHTML/Templates/NamePerCountDisplay.cshtml @@ -26,10 +26,9 @@ int height = 100+nameCount.Count() * 20; var xaxis = "[" + string.Join(',', nameCount - .Select(it => it.Name) + .Select(it => it.NameInJS()) .Select(it => it.Replace("<", "#60;")) .Select(it => it.Replace(">", "#62;")) - .Select(it => "\"" + it + "\"") .ToArray()) + "]"; var maxCount = nameCount.Max(it => it.Count); @@ -40,7 +39,7 @@ { nameCountGraphic = nameCount.Take(10).ToArray(); } - string assNamesMaintIndex = string.Join(",", nameCountGraphic.Select(it => "'" + it.Name.Replace("\\", "\\\\") + "'")); + string assNamesMaintIndex = string.Join(",", nameCountGraphic.Select(it => "'" + it.NameInJS() + "'")); string valuesMaintIndex = string.Join(",\r\n", nameCountGraphic.Select(it => "{value:" + it.Count +"}") ); @@ -125,7 +124,7 @@ bar @yAxis @foreach (var item in nameCountOriginal) { - {"Name": "@item.Name.Replace("\\", "\\\\")", "Nr": "@item.Count" }, + {"Name": "@item.NameInJS()", "Nr": "@item.Count" }, } ]; diff --git a/src/NetPackageAnalyzer/NetPackageAnalyzerExportHTML/Templates/NamePerCountDisplayThreshold.cshtml b/src/NetPackageAnalyzer/NetPackageAnalyzerExportHTML/Templates/NamePerCountDisplayThreshold.cshtml index 4be2185..42cf2ff 100644 --- a/src/NetPackageAnalyzer/NetPackageAnalyzerExportHTML/Templates/NamePerCountDisplayThreshold.cshtml +++ b/src/NetPackageAnalyzer/NetPackageAnalyzerExportHTML/Templates/NamePerCountDisplayThreshold.cshtml @@ -42,7 +42,7 @@ //threshold1 = 40; //threshold2 = 80; - string assNamesMaintIndex = string.Join(",", nameCountGraphic.Select(it => "'" + it.Name + "'")); + string assNamesMaintIndex = string.Join(",", nameCountGraphic.Select(it => "'" + it.NameInJS() + "'")); string valuesMaintIndex = string.Join(",\r\n", nameCountGraphic.Select(it => "{value:" + it.Count + (CompareT(it.Count, threshold1, inverseData) ? ",itemStyle:{color:'red'}" @@ -128,7 +128,7 @@ @foreach (var item in nameCount) { - {"Name": "@item.Name", "Nr": "@item.Count" }, + {"Name": "@item.NameInJS()", "Nr": "@item.Count" }, } ]; @@ -153,7 +153,7 @@ @{ if (display2.Length > 0) { - assNamesMaintIndex = string.Join(",", display2.Select(it => "'" + it.Name + "'")); + assNamesMaintIndex = string.Join(",", display2.Select(it => "'" + it.NameInJS() + "'")); var displayValues = nameCount .Select(it => "{value:" + it.Count + ",itemStyle:{color:'red'}}" diff --git a/src/NetPackageAnalyzer/NetPackageAnalyzerObjects/many.cs b/src/NetPackageAnalyzer/NetPackageAnalyzerObjects/many.cs index 36eb5d0..5ad67e6 100644 --- a/src/NetPackageAnalyzer/NetPackageAnalyzerObjects/many.cs +++ b/src/NetPackageAnalyzer/NetPackageAnalyzerObjects/many.cs @@ -39,6 +39,13 @@ public class PublicClassRefData public record NamePerCount(string Name, long Count) { + + public string NameInJS() + { + return Name + .Replace("\\", "\\\\") + .Replace("\"", "\\\""); + } public string AdditionalData { get; set; } = Name; }