Commit db430673 authored by Robert Speicher's avatar Robert Speicher

Merge branch '27296-incorrect-task-list-checked-with-embedded-subtasks' into 'master'

Incorrect task list checked with embedded subtasks

See merge request gitlab-org/gitlab!21947
parents 44f9ad79 91776d93
......@@ -15,11 +15,11 @@ module Taskable
INCOMPLETE_PATTERN = /(\[[\s]\])/.freeze
ITEM_PATTERN = %r{
^
(?:(?:>\s{0,4})*) # optional blockquote characters
\s*(?:[-+*]|(?:\d+\.)) # list prefix 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
(\s.+) # followed by whitespace and some text.
(?:(?:>\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
(\s.+) # followed by whitespace and some text.
}x.freeze
def self.get_tasks(content)
......
---
title: Properly check a task embedded in a list with no text
merge_request: 21947
author:
type: fixed
......@@ -121,7 +121,7 @@ describe TaskListToggleService do
> * [x] Task 2
EOT
markdown_html = Banzai::Pipeline::FullPipeline.call(markdown, project: nil)[:output].to_html
markdown_html = parse_markdown(markdown)
toggler = described_class.new(markdown, markdown_html,
toggle_as_checked: true,
line_source: '> > * [ ] Task 1', line_number: 1)
......@@ -142,7 +142,7 @@ describe TaskListToggleService do
* [x] Task 2
EOT
markdown_html = Banzai::Pipeline::FullPipeline.call(markdown, project: nil)[:output].to_html
markdown_html = parse_markdown(markdown)
toggler = described_class.new(markdown, markdown_html,
toggle_as_checked: true,
line_source: '* [ ] Task 1', line_number: 5)
......@@ -151,4 +151,44 @@ describe TaskListToggleService do
expect(toggler.updated_markdown.lines[4]).to eq "* [x] Task 1\n"
expect(toggler.updated_markdown_html).to include('disabled checked> Task 1')
end
context 'when clicking an embedded subtask' do
it 'properly handles it inside an unordered list' do
markdown =
<<-EOT.strip_heredoc
- - [ ] Task 1
- [x] Task 2
EOT
markdown_html = parse_markdown(markdown)
toggler = described_class.new(markdown, markdown_html,
toggle_as_checked: true,
line_source: '- - [ ] Task 1', line_number: 1)
expect(toggler.execute).to be_truthy
expect(toggler.updated_markdown.lines[0]).to eq "- - [x] Task 1\n"
expect(toggler.updated_markdown_html).to include('disabled checked> Task 1')
end
it 'properly handles it inside an ordered list' do
markdown =
<<-EOT.strip_heredoc
1. - [ ] Task 1
- [x] Task 2
EOT
markdown_html = parse_markdown(markdown)
toggler = described_class.new(markdown, markdown_html,
toggle_as_checked: true,
line_source: '1. - [ ] Task 1', line_number: 1)
expect(toggler.execute).to be_truthy
expect(toggler.updated_markdown.lines[0]).to eq "1. - [x] Task 1\n"
expect(toggler.updated_markdown_html).to include('disabled checked> Task 1')
end
end
def parse_markdown(markdown)
Banzai::Pipeline::FullPipeline.call(markdown, project: nil)[:output].to_html
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment