From d18df2cd915765dd1320e9009bf698335d8c7728 Mon Sep 17 00:00:00 2001 From: Thomas Chandelle Date: Mon, 14 Feb 2022 22:46:54 +0100 Subject: [PATCH 1/2] Check task with no-break space Use the [[:space:]] instead of \s in task list regexp. This is the same as the gem task_list Changelog: fixed --- app/models/concerns/taskable.rb | 8 ++++--- spec/models/concerns/taskable_spec.rb | 10 ++++++++- .../services/task_list_toggle_service_spec.rb | 21 +++++++++++++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/taskable.rb b/app/models/concerns/taskable.rb index e41a0ca28f928e..904c96b11b310c 100644 --- a/app/models/concerns/taskable.rb +++ b/app/models/concerns/taskable.rb @@ -11,14 +11,16 @@ module Taskable COMPLETED = 'completed' INCOMPLETE = 'incomplete' - COMPLETE_PATTERN = /(\[[xX]\])/.freeze - INCOMPLETE_PATTERN = /(\[\s\])/.freeze + COMPLETE_PATTERN = /\[[xX]\]/.freeze + INCOMPLETE_PATTERN = /\[[[:space:]]\]/.freeze ITEM_PATTERN = %r{ ^ (?:(?:>\s{0,4})*) # optional blockquote characters ((?:\s*(?:[-+*]|(?:\d+\.)))+) # list prefix (one or more) required - task item has to be always in a list \s+ # whitespace prefix has to be always presented for a list item - (\[\s\]|\[[xX]\]) # checkbox + ( # checkbox + #{COMPLETE_PATTERN}|#{INCOMPLETE_PATTERN} + ) (\s.+) # followed by whitespace and some text. }x.freeze diff --git a/spec/models/concerns/taskable_spec.rb b/spec/models/concerns/taskable_spec.rb index 6b41174a046179..140f6cda51cc02 100644 --- a/spec/models/concerns/taskable_spec.rb +++ b/spec/models/concerns/taskable_spec.rb @@ -13,6 +13,10 @@ - [x] Second item * [x] First item * [ ] Second item + + [ ] No-break space (U+00A0) + + [ ] Figure space (U+2007) + + [ ] Narrow no-break space (U+202F) + + [ ] Thin space (U+2009) MARKDOWN end @@ -21,7 +25,11 @@ TaskList::Item.new('- [ ]', 'First item'), TaskList::Item.new('- [x]', 'Second item'), TaskList::Item.new('* [x]', 'First item'), - TaskList::Item.new('* [ ]', 'Second item') + TaskList::Item.new('* [ ]', 'Second item'), + TaskList::Item.new('+ [ ]', 'No-break space (U+00A0)'), + TaskList::Item.new('+ [ ]', 'Figure space (U+2007)'), + TaskList::Item.new('+ [ ]', 'Narrow no-break space (U+202F)'), + TaskList::Item.new('+ [ ]', 'Thin space (U+2009)') ] end diff --git a/spec/services/task_list_toggle_service_spec.rb b/spec/services/task_list_toggle_service_spec.rb index 81f80ee926a4b3..f889f298213078 100644 --- a/spec/services/task_list_toggle_service_spec.rb +++ b/spec/services/task_list_toggle_service_spec.rb @@ -16,6 +16,8 @@ - [ ] loose list with an embedded paragraph + + + [ ] No-break space (U+00A0) EOT end @@ -40,12 +42,17 @@ -