Merge pull request #4247 from tchak/fix-export-xls

Fix invalid characters in repetition champs sheet_name for xls export
This commit is contained in:
Paul Chavard 2019-08-28 11:00:18 +02:00 committed by GitHub
commit 686e035431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -70,6 +70,10 @@ class ProcedureExportV2Service
row_style: { background_color: nil, color: "000000", font_size: 12 }
}
def sanitize_sheet_name(name)
ActiveStorage::Filename.new(name.to_s).sanitized.truncate(30)
end
def options_for(table)
case table
when :dossiers
@ -80,7 +84,7 @@ class ProcedureExportV2Service
{ instances: avis.to_a, sheet_name: 'Avis' }.merge(DEFAULT_STYLES)
when Array
# We have to truncate the label here as spreadsheets have a (30 char) limit on length.
{ instances: table.last, sheet_name: table.first.to_s.truncate(30) }.merge(DEFAULT_STYLES)
{ instances: table.last, sheet_name: sanitize_sheet_name(table.first) }.merge(DEFAULT_STYLES)
end
end
end

View file

@ -184,6 +184,16 @@ describe ProcedureExportV2Service do
it 'should have data' do
expect(repetition_sheet.data.size).to eq(4)
end
context 'with invalid characters' do
before do
champ_repetition.type_de_champ.update(libelle: 'A / B \ C')
end
it 'should have valid sheet name' do
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', "A - B - C"])
end
end
end
end
end