Skip to content

Prevent unintended rendering of report content #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions reportsizedeltas/reportsizedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def add_summary_report_row(self, report_data, fqbn_data):
row_number = len(report_data)
# Add a row to the report
row = ["" for _ in range(len(report_data[0]))]
row[0] = fqbn_data[self.ReportKeys.board]
row[0] = "`{board_name}`".format(board_name=fqbn_data[self.ReportKeys.board])
report_data.append(row)

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

# Populate the row with data
Expand All @@ -453,8 +453,10 @@ def add_detailed_report_row(self, report_data, fqbn_data):
column_number = get_report_column_number(
report=report_data,
column_heading=(
sketch[self.ReportKeys.name] + "<br>"
+ size_data[self.ReportKeys.name]
"`{sketch_name}`<br>{size_name}".format(
sketch_name=sketch[self.ReportKeys.name],
size_name=size_data[self.ReportKeys.name]
)
)
)

Expand Down Expand Up @@ -776,7 +778,16 @@ def generate_csv_table(row_list):
csv_string = io.StringIO()
csv_writer = csv.writer(csv_string, lineterminator="\n")
for row in row_list:
csv_writer.writerow(row)
cleaned_row = []
for cell in row:
cleaned_cell = cell
if isinstance(cleaned_cell, str):
# The "code span" markup is not needed in the CSV report.
cleaned_cell = cleaned_cell.replace("`", "")

cleaned_row.append(cleaned_cell)

csv_writer.writerow(cleaned_row)

return csv_string.getvalue()

Expand Down
38 changes: 19 additions & 19 deletions reportsizedeltas/tests/test_reportsizedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def test_get_sketches_reports(sketches_reports_path, expected_sketches_reports):
[
["Board", "flash", "%", "RAM for global variables", "%"],
[
"arduino:avr:uno",
"`arduino:avr:uno`",
":green_heart: -994 - -994",
"-3.08 - -3.08",
":green_heart: -175 - -175",
Expand All @@ -865,7 +865,7 @@ def test_get_sketches_reports(sketches_reports_path, expected_sketches_reports):
[
["Board", "flash", "%", "RAM for global variables", "%"],
[
"arduino:avr:uno",
"`arduino:avr:uno`",
":green_heart: -994 - -994",
"-3.08 - -3.08",
":green_heart: -175 - -175",
Expand All @@ -888,13 +888,13 @@ def test_get_sketches_reports(sketches_reports_path, expected_sketches_reports):
[
["Board", "flash", "%", "RAM for global variables", "%"],
[
"arduino:avr:uno",
"`arduino:avr:uno`",
":green_heart: -994 - -994",
"-3.08 - -3.08",
":green_heart: -175 - -175",
"-8.54 - -8.54"
],
["arduino:mbed_portenta:envie_m7", "N/A", "N/A", "N/A", "N/A"]
["`arduino:mbed_portenta:envie_m7`", "N/A", "N/A", "N/A", "N/A"]
]
)
]
Expand Down Expand Up @@ -955,14 +955,14 @@ def test_add_summary_report_row(report_data, fqbn_data, expected_report_data):
]
},
[
["Board", "examples/Foo<br>flash", "%", "examples/Foo<br>RAM for global variables", "%"],
["arduino:avr:leonardo", -12, -0.05, 0, -0.0]
["Board", "`examples/Foo`<br>flash", "%", "`examples/Foo`<br>RAM for global variables", "%"],
["`arduino:avr:leonardo`", -12, -0.05, 0, -0.0]
]
),
(
[
["Board", "examples/Foo<br>flash", "%", "examples/Foo<br>RAM for global variables", "%"],
["arduino:avr:leonardo", -12, -0.05, 0, -0.0]
["Board", "`examples/Foo`<br>flash", "%", "`examples/Foo`<br>RAM for global variables", "%"],
["`arduino:avr:leonardo`", -12, -0.05, 0, -0.0]
],
{
report_keys.board: "arduino:mbed_portenta:envie_m7",
Expand Down Expand Up @@ -992,9 +992,9 @@ def test_add_summary_report_row(report_data, fqbn_data, expected_report_data):
]
},
[
["Board", "examples/Foo<br>flash", "%", "examples/Foo<br>RAM for global variables", "%"],
["arduino:avr:leonardo", -12, -0.05, 0, -0.0],
["arduino:mbed_portenta:envie_m7", "N/A", "N/A", "N/A", "N/A"]
["Board", "`examples/Foo`<br>flash", "%", "`examples/Foo`<br>RAM for global variables", "%"],
["`arduino:avr:leonardo`", -12, -0.05, 0, -0.0],
["`arduino:mbed_portenta:envie_m7`", "N/A", "N/A", "N/A", "N/A"]
]
)
]
Expand All @@ -1012,17 +1012,17 @@ def test_generate_report():
"**Memory usage change @ d8fd302**\n\n"
"Board|flash|%|RAM for global variables|%\n"
"-|-|-|-|-\n"
"arduino:avr:leonardo|:green_heart: -12 - -12|-0.05 - -0.05|0 - 0|0.0 - 0.0\n"
"arduino:avr:uno|:green_heart: -994 - -994|-3.08 - -3.08|:green_heart: -175 - -175|-8.54 - -8.54\n"
"arduino:mbed_portenta:envie_m7|N/A|N/A|N/A|N/A\n\n"
"`arduino:avr:leonardo`|:green_heart: -12 - -12|-0.05 - -0.05|0 - 0|0.0 - 0.0\n"
"`arduino:avr:uno`|:green_heart: -994 - -994|-3.08 - -3.08|:green_heart: -175 - -175|-8.54 - -8.54\n"
"`arduino:mbed_portenta:envie_m7`|N/A|N/A|N/A|N/A\n\n"
"<details>\n"
"<summary>Click for full report table</summary>\n\n"
"Board|examples/Bar<br>flash|%|examples/Bar<br>RAM for global variables|%|examples/Foo<br>flash|%|examples/Foo"
"<br>RAM for global variables|%\n"
"Board|`examples/Bar`<br>flash|%|`examples/Bar`<br>RAM for global variables|%|`examples/Foo`<br>flash|%|"
"`examples/Foo`<br>RAM for global variables|%\n"
"-|-|-|-|-|-|-|-|-\n"
"arduino:avr:leonardo|N/A|N/A|N/A|N/A|-12|-0.05|0|0.0\n"
"arduino:avr:uno|N/A|N/A|N/A|N/A|-994|-3.08|-175|-8.54\n"
"arduino:mbed_portenta:envie_m7|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A\n\n"
"`arduino:avr:leonardo`|N/A|N/A|N/A|N/A|-12|-0.05|0|0.0\n"
"`arduino:avr:uno`|N/A|N/A|N/A|N/A|-994|-3.08|-175|-8.54\n"
"`arduino:mbed_portenta:envie_m7`|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A\n\n"
"</details>\n\n"
"<details>\n"
"<summary>Click for full report CSV</summary>\n\n"
Expand Down