Skip to content
This repository was archived by the owner on Nov 1, 2017. It is now read-only.

Commit dd204f9

Browse files
committed
Match all whitespace
This might be too inclusive. And doesn't address the XPath matching.
1 parent 3e38fe4 commit dd204f9

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/task_list/filter.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ def self.filter(*args)
3131
# :task_list_items - An array of TaskList::Item objects.
3232
class Filter < HTML::Pipeline::Filter
3333

34-
Incomplete = "[ ]".freeze
35-
IncompleteNBSP = "[\xC2\xA0]".freeze
36-
Complete = "[x]".freeze
34+
Incomplete = "[ ]".freeze
35+
Complete = "[x]".freeze
36+
37+
IncompletePattern = /\[[[:space:]]\]/.freeze # matches all whitespace
38+
CompletePattern = Regexp.escape(Complete).freeze
3739

3840
# Pattern used to identify all task list items.
3941
# Useful when you need iterate over all items.
@@ -42,9 +44,8 @@ class Filter < HTML::Pipeline::Filter
4244
(?:\s*[-+*]|(?:\d+\.))? # optional list prefix
4345
\s* # optional whitespace prefix
4446
( # checkbox
45-
#{Regexp.escape(Complete)}|
46-
#{Regexp.escape(Incomplete)}|
47-
#{Regexp.escape(IncompleteNBSP)}
47+
#{CompletePattern}|
48+
#{IncompletePattern}
4849
)
4950
(?=\s) # followed by whitespace
5051
/x
@@ -53,11 +54,9 @@ class Filter < HTML::Pipeline::Filter
5354
# select UL/OL
5455
".//li[starts-with(text(),'[ ]')]/..",
5556
".//li[starts-with(text(),'[x]')]/..",
56-
".//li[starts-with(text(),'[\xC2\xA0]')]/..",
5757
# and those wrapped in Ps
5858
".//li/p[1][starts-with(text(),'[ ]')]/../..",
59-
".//li/p[1][starts-with(text(),'[x]')]/../..",
60-
".//li/p[1][starts-with(text(),'[\xC2\xA0]')]/../.."
59+
".//li/p[1][starts-with(text(),'[x]')]/../.."
6160
].join(' | ').freeze
6261

6362
# Selects all LIs from a TaskList UL/OL

test/task_list/filter_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,24 @@ def test_handles_encoding_correctly
8080

8181
# NOTE: This is an edge case experienced regularly by users using a Swiss
8282
# German keyboard.
83+
# See: https://github.com/github/github/pull/18362
8384
def test_non_breaking_space_between_brackets
8485
text = "- [\xC2\xA0] ok"
8586
assert item = filter(text)[:output].css('.task-list-item').pop, "item expected"
8687
assert_equal 'ok', item.text.strip
8788
end
8889

90+
# See: https://github.com/github/github/pull/18362
91+
def test_non_breaking_space_between_brackets_in_paras
92+
text = <<-md
93+
- [\xC2\xA0] one
94+
- [\xC2\xA0] this one will be wrapped in a para
95+
96+
- [\xC2\xA0] this one too, wtf
97+
md
98+
assert_equal 3, filter(text)[:output].css(@item_selector).size
99+
end
100+
89101
protected
90102

91103
def filter(input, context = @context, result = nil)

0 commit comments

Comments
 (0)