-
Notifications
You must be signed in to change notification settings - Fork 55
Updates should not ignore items with links #41
Conversation
Could use some regexp help... struggling to distinguish when to update between these scenarios: - [ ] one
- [ ] [two] # skip this
- [ ] (three) # and skip this
- [ ] [four] (url) # but not this
- [ ] [five] [ref] # nor this
- [ ] six |
Do you know what line of code is failing? |
@aroben essentially, this stanza of the task_list/app/assets/javascripts/task_list.coffee Lines 128 to 131 in b3b4514
But it needs to look further ahead to make sure that it isn't a task list followed by a link. Feels like a fools errand. Might be worth splitting up the pattern matching to have an explicit ignore step that can better handle this kind of matching. |
Here's a scriptular reproduction to play with: http://bit.ly/ZePF7z |
Seems like we want to skip even sequences of square bracket pairs. I.e.: Skip:
Don't skip:
I'm sure there's some regex-fu that would do this given that JS regexes support back references. |
@aroben heh, that's a good observation. Will play around with that. This is particularly frustrating since we're having to ignore what's essentially a mistake, In pseudocode, I'm thinking: match item, but not if it's actually a link, unless that link is a independent and separate from the checkbox. The wording may be confusing, but it's the "not...unless" part that seems intractable right now. |
I think of it like this: We match if:
1 and 2 are easy. 3 is a little tricky, but I think doable. |
@aroben number 2 is incomplete since |
Item 3 handles that case. The item must be followed by an even number of [] pairs. In your example it's followed by 1 [] pair. -Adam
|
@aroben 👍 good point. Taking another swing at it now. |
I think I was wrong about needing back references before. I think you can use a negative lookahead assertion to handle the ///
# the good stuff goes here
(?!\s*\(.*?\)) # Not a [foo](url) link
(?=
\s*
(?:\[.*?\]\s*){2}* # Must be followed by an even number of [] pairs (including 0)
(?:[^[]|$) # After all the pairs comes either something that's not a [, or the end of the line
)
/// |
Still fails, though. cc @aroben
(?! # is not a link | ||
\s* # with optional whitespace | ||
(?:\(.*?\)|\[.*?\]) # because of destination or reference | ||
) | ||
(?=\s) # is followed by whitespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably needs to be \s+
so that there can be more than one whitespace character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I guess extra whitespace characters don't need to be matched here. They'll just be after the pattern (or consumed by \s*
in the subsequent assertions).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a lookahead assertion at all? Would a bare \s
work not enclosed in (?=)
? (This may be unrelated to fixing this bug.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aroben lookahead probably isn't needed. Agreed on the extra whitespace not needing to be matched here. Unrelated to the issue, I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think removing the (?=)
makes the test pass. Give it a try!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem is that when you have two positive lookahead assertions in a row they both need to match. Instead we want the \s
to match and then the reference stuff to come after that.
I'm to the point where I think it'd just be better to only handle the |
Punting on proper handling for now.
@aroben this is what I have right now, and it's still failing: diff --git a/app/assets/javascripts/task_list.coffee b/app/assets/javascripts/task_list.coffee
index f5cf946..7fec188 100644
--- a/app/assets/javascripts/task_list.coffee
+++ b/app/assets/javascripts/task_list.coffee
@@ -125,11 +125,21 @@ itemPattern = ///
#{escapePattern(complete)}|
#{escapePattern(incomplete)}
)
- (?=\s) # is followed by whitespace
+ \s # is followed by whitespace
(?! # but not a link to this destination
\s*
\(.*?\)
)
+ (?= # and not part of a link reference
+ \s*
+ (?:(?:\[.*?\]\s*){2})*
+ (?:[^\[]|$)
+ )
///
# Used to filter out code fences from the source for comparison only.
|
Hm, strange. In both Safari and Chrome's console things seem to work the way we want: /^(?:\s*(?:>\s*)*(?:[-+*]|(?:\d+\.)))\s*(\[\s\]|\[[xX]\])\s(?!\s*\(.*?\))(?=\s*(?:(?:\[.*?\]\s*){2})*(?:[^\[]|$))/.exec("- [ ] [reference label][reference]")
["- [ ] ", "[ ]"] …so why isn't it passing the test? |
Oh, maybe phantomjs has a too-old JS engine. |
Yup, that's the problem:
|
I wonder if this is fixed in PhantomJS 2 /cc @eanakashima |
Reproduced something that works here: http://bit.ly/ZfhL2s @aroben seems that 765f60f works. Does that make sense to you? |
Here's my PhantomJS version locally:
It looks like earlier changes are passing in CI (6+ minute long builds for the loss) which makes this sound reasonable. Hopefully this most recent change will work though. Update: 6+ minutes, not 20+. |
Not loving regexp right meow 😼 |
@aroben legit, let's see how CI feels about it. |
Feeling that the style of testing employed here is masking which items are being ignored, which can lead us astray (pretty sure that happened a few times today). Need to make writing these tests much easier and simpler. |
Updates should not ignore items with links
@aroben really appreciate the help here. The brink of sanity is a scary place. ❤️ |
👬 |
Appears not to be. I also get |
A regression as part of #38 is that items followed immediately by links get ignored on update. Whoops. Here's a failing test to reproduce the user reported issue so we can work towards a fix.
cc @github/task-lists @rsese @aroben