Skip to content
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

Hl 1048 bom #2495

Merged
merged 2 commits into from
Nov 22, 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
8 changes: 6 additions & 2 deletions backend/benefit/applications/services/csv_export_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def write_csv_file(self, path) -> None:

def get_csv_string(self, remove_quotes: bool = False) -> str:
return "".join( # Lines end with '\r\n' already so no need to add newlines here
self.get_csv_string_lines_generator(remove_quotes=remove_quotes)
self.get_csv_string_lines_generator(
remove_quotes=remove_quotes, add_bom=True
)
)

def get_csv_cell_list_lines_generator(
Expand Down Expand Up @@ -138,7 +140,9 @@ def get_csv_string_lines_generator(

for line in self.get_csv_cell_list_lines_generator():
line_length_set.add(len(line))
assert len(line_length_set) == 1, "Each CSV line must have same colum count"
assert (
len(line_length_set) == 1
), "Each CSV line must have same column count"
csv_writer.writerow(line)
yield io.getvalue()
# Reset StringIO object
Expand Down
13 changes: 8 additions & 5 deletions backend/benefit/applications/tests/test_applications_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ def test_pruned_applications_csv_output(
application = (
pruned_applications_csv_service_with_one_application.get_applications()[0]
)
# Assert that there are 15 column headers in the pruned CSV
# Assert that there are 18 column headers in the pruned CSV
assert len(csv_lines[0]) == 18

assert csv_lines[0][0] == '"Hakemusnumero"'
assert csv_lines[0][0] == '\ufeff"Hakemusnumero"'
assert csv_lines[0][1] == '"TyΓΆnantajan tyyppi"'
assert csv_lines[0][2] == '"TyΓΆnantajan tilinumero"'
assert csv_lines[0][3] == '"TyΓΆnantajan nimi"'
Expand Down Expand Up @@ -357,7 +357,7 @@ def test_pruned_applications_csv_output(

def test_applications_csv_output(applications_csv_service): # noqa: C901
csv_lines = split_lines_at_semicolon(applications_csv_service.get_csv_string())
assert csv_lines[0][0] == '"Hakemusnumero"'
assert csv_lines[0][0] == '\ufeff"Hakemusnumero"'
assert (
int(csv_lines[1][0])
== applications_csv_service.get_applications()[0].application_number
Expand All @@ -370,7 +370,10 @@ def test_applications_csv_output(applications_csv_service): # noqa: C901
assert application.ahjo_rows[0].start_date == application.calculation.start_date
assert application.ahjo_rows[0].end_date == application.calculation.end_date

for idx, col in enumerate(applications_csv_service.CSV_COLUMNS):
csv_columns = iter(applications_csv_service.CSV_COLUMNS)
next(csv_columns, None) # Skip the first element

for idx, col in enumerate(csv_columns, start=1):
assert csv_lines[0][idx] == f'"{col.heading}"'

if "TyΓΆnantajan tyyppi" in col.heading:
Expand Down Expand Up @@ -495,7 +498,7 @@ def test_applications_csv_two_ahjo_rows(applications_csv_service_with_one_applic
applications_csv_service_with_one_application.get_csv_string()
)
assert len(application.ahjo_rows) == 2
assert csv_lines[0][0] == '"Hakemusnumero"'
assert csv_lines[0][0] == '\ufeff"Hakemusnumero"'
assert int(csv_lines[1][0]) == application.application_number
assert int(csv_lines[1][1]) == 1
assert int(csv_lines[2][0]) == application.application_number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_talpa_csv_output(pruned_applications_csv_service_with_one_application):
pruned_applications_csv_service_with_one_application.get_csv_string()
)
# BOM at the beginning of the file
assert csv_lines[0][0] == '"Hakemusnumero"'
assert csv_lines[0][0] == '\ufeff"Hakemusnumero"'
csv_columns = iter(pruned_applications_csv_service_with_one_application.CSV_COLUMNS)
next(csv_columns, None) # Skip the first element

Expand Down
2 changes: 1 addition & 1 deletion frontend/shared/src/utils/file.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const downloadFile = (data: string, type: ExportFileType): void => {

if (type === 'csv') {
// eslint-disable-next-line security/detect-non-literal-fs-filename
fileDownload(data, `hl ${dateString}.csv`, 'text/csv;charset=utf-8');
fileDownload(data, `hl ${dateString}.csv`, 'text/csv;charset=utf-8-sig', '\uFEFF');
} else {
fileDownload(data, `hl ${dateString}.zip`);
}
Expand Down