fix(dossier): tag can contain non breaking space

This commit is contained in:
Paul Chavard 2022-10-21 16:19:08 +02:00
parent d7c5dcf8bb
commit f2e8dba8e4
3 changed files with 11 additions and 2 deletions

View file

@ -42,7 +42,7 @@ module TagsSubstitutionConcern
define_combinator :tag_text do
join(single(tag_text_first_char) + many(tag_text_char)).fmap do |str|
str.force_encoding('utf-8').encode
str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ')
end
end

View file

@ -15,7 +15,7 @@ class TypesDeChamp::TypeDeChampBase
stable_id = self.stable_id
[
{
libelle: libelle,
libelle: libelle.gsub(/[[:space:]]/, ' '),
id: "tdc#{stable_id}",
description: description,
lambda: -> (champs) {

View file

@ -519,5 +519,14 @@ describe TagsSubstitutionConcern, type: :model do
{ tag: "numéro-du - dossier" }
])
end
it 'normalize white spaces' do
tokens = TagsSubstitutionConcern::TagsParser.parse("hello --Jour(s) fixe(s)\xc2\xA0souhaité(s)\xc2\xA0:-- world".encode('utf-8'))
expect(tokens).to eq([
{ text: "hello " },
{ tag: "Jour(s) fixe(s) souhaité(s) :" },
{ text: " world" }
])
end
end
end