Merge pull request #4725 from betagouv/fix-export-excel-invalid-worksheet

Fix - Suppression des caractères invalides pour feuilles excel
This commit is contained in:
Paul Chavard 2020-01-29 11:21:00 +00:00 committed by GitHub
commit 5bd4c16de8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -36,7 +36,8 @@ class Champs::RepetitionChamp < Champ
# We have to truncate the label here as spreadsheets have a (30 char) limit on length.
def libelle_for_export
str = "(#{type_de_champ.stable_id}) #{libelle}"
ActiveStorage::Filename.new(str).sanitized.truncate(30)
# /\*?[] are invalid Excel worksheet characters
ActiveStorage::Filename.new(str.delete('[]*?')).sanitized.truncate(30)
end
class Row < Hashie::Dash

View file

@ -334,7 +334,7 @@ describe ProcedureExportService do
context 'with invalid characters' do
before do
champ_repetition.type_de_champ.update(libelle: 'A / B \ C')
champ_repetition.type_de_champ.update(libelle: 'A / B \ C *[]?')
end
it 'should have valid sheet name' do