Skip to content

Commit a22a921

Browse files
authored
Merge pull request #32 from per1234/unintentional-emoji
Prevent unintended rendering of report content
2 parents 239ce6d + 5cbb096 commit a22a921

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

reportsizedeltas/reportsizedeltas.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def add_summary_report_row(self, report_data, fqbn_data):
380380
row_number = len(report_data)
381381
# Add a row to the report
382382
row = ["" for _ in range(len(report_data[0]))]
383-
row[0] = fqbn_data[self.ReportKeys.board]
383+
row[0] = "`{board_name}`".format(board_name=fqbn_data[self.ReportKeys.board])
384384
report_data.append(row)
385385

386386
# Populate the row with data
@@ -443,7 +443,7 @@ def add_detailed_report_row(self, report_data, fqbn_data):
443443
row_number = len(report_data)
444444
# Add a row to the report
445445
row = ["" for _ in range(len(report_data[0]))]
446-
row[0] = fqbn_data[self.ReportKeys.board]
446+
row[0] = "`{board_name}`".format(board_name=fqbn_data[self.ReportKeys.board])
447447
report_data.append(row)
448448

449449
# Populate the row with data
@@ -453,8 +453,10 @@ def add_detailed_report_row(self, report_data, fqbn_data):
453453
column_number = get_report_column_number(
454454
report=report_data,
455455
column_heading=(
456-
sketch[self.ReportKeys.name] + "<br>"
457-
+ size_data[self.ReportKeys.name]
456+
"`{sketch_name}`<br>{size_name}".format(
457+
sketch_name=sketch[self.ReportKeys.name],
458+
size_name=size_data[self.ReportKeys.name]
459+
)
458460
)
459461
)
460462

@@ -776,7 +778,16 @@ def generate_csv_table(row_list):
776778
csv_string = io.StringIO()
777779
csv_writer = csv.writer(csv_string, lineterminator="\n")
778780
for row in row_list:
779-
csv_writer.writerow(row)
781+
cleaned_row = []
782+
for cell in row:
783+
cleaned_cell = cell
784+
if isinstance(cleaned_cell, str):
785+
# The "code span" markup is not needed in the CSV report.
786+
cleaned_cell = cleaned_cell.replace("`", "")
787+
788+
cleaned_row.append(cleaned_cell)
789+
790+
csv_writer.writerow(cleaned_row)
780791

781792
return csv_string.getvalue()
782793

reportsizedeltas/tests/test_reportsizedeltas.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ def test_get_sketches_reports(sketches_reports_path, expected_sketches_reports):
853853
[
854854
["Board", "flash", "%", "RAM for global variables", "%"],
855855
[
856-
"arduino:avr:uno",
856+
"`arduino:avr:uno`",
857857
":green_heart: -994 - -994",
858858
"-3.08 - -3.08",
859859
":green_heart: -175 - -175",
@@ -865,7 +865,7 @@ def test_get_sketches_reports(sketches_reports_path, expected_sketches_reports):
865865
[
866866
["Board", "flash", "%", "RAM for global variables", "%"],
867867
[
868-
"arduino:avr:uno",
868+
"`arduino:avr:uno`",
869869
":green_heart: -994 - -994",
870870
"-3.08 - -3.08",
871871
":green_heart: -175 - -175",
@@ -888,13 +888,13 @@ def test_get_sketches_reports(sketches_reports_path, expected_sketches_reports):
888888
[
889889
["Board", "flash", "%", "RAM for global variables", "%"],
890890
[
891-
"arduino:avr:uno",
891+
"`arduino:avr:uno`",
892892
":green_heart: -994 - -994",
893893
"-3.08 - -3.08",
894894
":green_heart: -175 - -175",
895895
"-8.54 - -8.54"
896896
],
897-
["arduino:mbed_portenta:envie_m7", "N/A", "N/A", "N/A", "N/A"]
897+
["`arduino:mbed_portenta:envie_m7`", "N/A", "N/A", "N/A", "N/A"]
898898
]
899899
)
900900
]
@@ -955,14 +955,14 @@ def test_add_summary_report_row(report_data, fqbn_data, expected_report_data):
955955
]
956956
},
957957
[
958-
["Board", "examples/Foo<br>flash", "%", "examples/Foo<br>RAM for global variables", "%"],
959-
["arduino:avr:leonardo", -12, -0.05, 0, -0.0]
958+
["Board", "`examples/Foo`<br>flash", "%", "`examples/Foo`<br>RAM for global variables", "%"],
959+
["`arduino:avr:leonardo`", -12, -0.05, 0, -0.0]
960960
]
961961
),
962962
(
963963
[
964-
["Board", "examples/Foo<br>flash", "%", "examples/Foo<br>RAM for global variables", "%"],
965-
["arduino:avr:leonardo", -12, -0.05, 0, -0.0]
964+
["Board", "`examples/Foo`<br>flash", "%", "`examples/Foo`<br>RAM for global variables", "%"],
965+
["`arduino:avr:leonardo`", -12, -0.05, 0, -0.0]
966966
],
967967
{
968968
report_keys.board: "arduino:mbed_portenta:envie_m7",
@@ -992,9 +992,9 @@ def test_add_summary_report_row(report_data, fqbn_data, expected_report_data):
992992
]
993993
},
994994
[
995-
["Board", "examples/Foo<br>flash", "%", "examples/Foo<br>RAM for global variables", "%"],
996-
["arduino:avr:leonardo", -12, -0.05, 0, -0.0],
997-
["arduino:mbed_portenta:envie_m7", "N/A", "N/A", "N/A", "N/A"]
995+
["Board", "`examples/Foo`<br>flash", "%", "`examples/Foo`<br>RAM for global variables", "%"],
996+
["`arduino:avr:leonardo`", -12, -0.05, 0, -0.0],
997+
["`arduino:mbed_portenta:envie_m7`", "N/A", "N/A", "N/A", "N/A"]
998998
]
999999
)
10001000
]
@@ -1012,17 +1012,17 @@ def test_generate_report():
10121012
"**Memory usage change @ d8fd302**\n\n"
10131013
"Board|flash|%|RAM for global variables|%\n"
10141014
"-|-|-|-|-\n"
1015-
"arduino:avr:leonardo|:green_heart: -12 - -12|-0.05 - -0.05|0 - 0|0.0 - 0.0\n"
1016-
"arduino:avr:uno|:green_heart: -994 - -994|-3.08 - -3.08|:green_heart: -175 - -175|-8.54 - -8.54\n"
1017-
"arduino:mbed_portenta:envie_m7|N/A|N/A|N/A|N/A\n\n"
1015+
"`arduino:avr:leonardo`|:green_heart: -12 - -12|-0.05 - -0.05|0 - 0|0.0 - 0.0\n"
1016+
"`arduino:avr:uno`|:green_heart: -994 - -994|-3.08 - -3.08|:green_heart: -175 - -175|-8.54 - -8.54\n"
1017+
"`arduino:mbed_portenta:envie_m7`|N/A|N/A|N/A|N/A\n\n"
10181018
"<details>\n"
10191019
"<summary>Click for full report table</summary>\n\n"
1020-
"Board|examples/Bar<br>flash|%|examples/Bar<br>RAM for global variables|%|examples/Foo<br>flash|%|examples/Foo"
1021-
"<br>RAM for global variables|%\n"
1020+
"Board|`examples/Bar`<br>flash|%|`examples/Bar`<br>RAM for global variables|%|`examples/Foo`<br>flash|%|"
1021+
"`examples/Foo`<br>RAM for global variables|%\n"
10221022
"-|-|-|-|-|-|-|-|-\n"
1023-
"arduino:avr:leonardo|N/A|N/A|N/A|N/A|-12|-0.05|0|0.0\n"
1024-
"arduino:avr:uno|N/A|N/A|N/A|N/A|-994|-3.08|-175|-8.54\n"
1025-
"arduino:mbed_portenta:envie_m7|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A\n\n"
1023+
"`arduino:avr:leonardo`|N/A|N/A|N/A|N/A|-12|-0.05|0|0.0\n"
1024+
"`arduino:avr:uno`|N/A|N/A|N/A|N/A|-994|-3.08|-175|-8.54\n"
1025+
"`arduino:mbed_portenta:envie_m7`|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A\n\n"
10261026
"</details>\n\n"
10271027
"<details>\n"
10281028
"<summary>Click for full report CSV</summary>\n\n"

0 commit comments

Comments
 (0)