Merge pull request #7950 from tchak/fix-tags-parser
fix(dossier): a tag can be preceded by a -
This commit is contained in:
commit
0eeb4d123e
3 changed files with 33 additions and 6 deletions
|
@ -32,9 +32,17 @@ module TagsSubstitutionConcern
|
|||
lit('--')
|
||||
end
|
||||
|
||||
define_combinator :tag_text_first_char do
|
||||
any_char.that_fail(lit('-') | tag_delimiter | eol)
|
||||
end
|
||||
|
||||
define_combinator :tag_text_char do
|
||||
any_char.that_fail(tag_delimiter | eol)
|
||||
end
|
||||
|
||||
define_combinator :tag_text do
|
||||
join(many(any_char.that_fail(tag_delimiter | eol))).fmap do |str|
|
||||
str.force_encoding('utf-8').encode
|
||||
join(single(tag_text_first_char) + many(tag_text_char)).fmap do |str|
|
||||
str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -99,7 +99,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
let(:types_de_champ_public) do
|
||||
[
|
||||
{ libelle: 'libelleA' },
|
||||
{ libelle: 'libelleB' }
|
||||
{ libelle: "libelle\xc2\xA0B".encode('utf-8') }
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -115,7 +115,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
end
|
||||
|
||||
context 'and they are used in the template' do
|
||||
let(:template) { '--libelleA-- --libelleB--' }
|
||||
let(:template) { '--libelleA-- --libelle B--' }
|
||||
|
||||
context 'and their value in the dossier are nil' do
|
||||
it { is_expected.to eq(' ') }
|
||||
|
@ -128,7 +128,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
.update(value: 'libelle1')
|
||||
|
||||
dossier.champs
|
||||
.find { |champ| champ.libelle == 'libelleB' }
|
||||
.find { |champ| champ.libelle == "libelle\xc2\xA0B".encode('utf-8') }
|
||||
.update(value: 'libelle2')
|
||||
end
|
||||
|
||||
|
@ -509,5 +509,24 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
{ text: " encore du text\n" + "---\n" + " encore du text" }
|
||||
])
|
||||
end
|
||||
|
||||
it 'allow for - before tag' do
|
||||
tokens = TagsSubstitutionConcern::TagsParser.parse("hello --yolo-- world ---numéro-du - dossier--")
|
||||
expect(tokens).to eq([
|
||||
{ text: "hello " },
|
||||
{ tag: "yolo" },
|
||||
{ text: " world -" },
|
||||
{ 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
|
||||
|
|
Loading…
Reference in a new issue