Merge pull request #8532 from tchak/fix-parser-with-dashes

fix(dossier): fix parser with dashes
This commit is contained in:
Paul Chavard 2023-01-31 11:20:00 +01:00 committed by GitHub
commit 570c06e53e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View file

@ -41,11 +41,11 @@ module TagsSubstitutionConcern
end
define_combinator :tag_text_first_char do
any_char.that_fail(lit('-') | tag_delimiter)
any_char.that_fail(lit('-') | tag_delimiter | eol)
end
define_combinator :tag_text_char do
any_char.that_fail(tag_delimiter)
any_char.that_fail(tag_delimiter | eol)
end
define_combinator :tag_text do
@ -53,6 +53,10 @@ module TagsSubstitutionConcern
str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ')
end
end
define_combinator :eol do
lit("\r\n") | lit("\n")
end
end
DOSSIER_TAGS = [

View file

@ -516,7 +516,7 @@ describe TagsSubstitutionConcern, type: :model do
describe 'parser' do
it do
tokens = TagsSubstitutionConcern::TagsParser.parse("hello world --public--, --numéro du dossier--, un test--yolo-- encore du text\n---\n encore du text")
tokens = TagsSubstitutionConcern::TagsParser.parse("hello world --public--, --numéro du dossier--, un test--yolo-- encore du text\n---\n encore du text --- et encore du text\n--tag--")
expect(tokens).to eq([
{ text: "hello world " },
{ tag: "public" },
@ -524,14 +524,15 @@ describe TagsSubstitutionConcern, type: :model do
{ tag: "numéro du dossier" },
{ text: ", un test" },
{ tag: "yolo" },
{ text: " encore du text\n" + "---\n" + " encore du text" }
{ text: " encore du text\n" + "---\n" + " encore du text --- et encore du text\n" },
{ tag: "tag" }
])
end
it 'allow for - before tag' do
tokens = TagsSubstitutionConcern::TagsParser.parse("hello --yolo-- -- before-- --after -- -- around -- world ---numéro-du - dossier--")
tokens = TagsSubstitutionConcern::TagsParser.parse("-----------------\nhello --yolo-- -- before-- --after -- -- around -- world ---numéro-du - dossier--")
expect(tokens).to eq([
{ text: "hello " },
{ text: "-----------------\nhello " },
{ tag: "yolo" },
{ text: " " },
{ tag: "before" },