Skip to content

Conversation

@Martin1887
Copy link
Collaborator

Fixes: #551

@Martin1887
Copy link
Collaborator Author

The algorithm is not easy to understand and it is almost undocumented, but it has no sense to me to start searching the stack in the stack's length (out of the stack), so the function only was doing something when the lower bound was less than the stack's length.

This change fix the issue #551 and does not break any test, but as I have not fully understood the algorithm I would like the @raphlinus or @marcusklaas validation.

Thanks.

src/parse.rs Outdated
both: bool,
) -> Option<InlineEl> {
let lowerbound = min(self.stack.len(), self.get_lowerbound(c, count, both));
if self.stack.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right, and it feels like it might be possible to construct failing cases. One is that the extra lookback in the stack needs more than 1. Another is that it fails to call set_lowerbound() in the case that the stack is empty.

@raphlinus
Copy link
Collaborator

raphlinus commented Jun 9, 2023

Consider the following patch instead, which fixes the case I looked at:

diff --git a/src/parse.rs b/src/parse.rs
index 1573d31..4d4c624 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -1062,7 +1062,14 @@ impl InlineStack {
         }
     }
 
+    fn trim_lower_bound(&mut self, ix: usize) {
+        self.lower_bounds[ix] = self.lower_bounds[ix].min(self.stack.len());
+    }
+
     fn push(&mut self, el: InlineEl) {
+        if el.c == b'~' {
+            self.trim_lower_bound(InlineStack::TILDES);
+        }
         self.stack.push(el)
     }
 }

It's also possible that there are other cases, in which case the if should be expanded into a match, and the lower bounds appropriate for that el.c be trimmed.

@Martin1887
Copy link
Collaborator Author

Thanks, Raph, this patch solves the issue.

@Martin1887 Martin1887 merged commit c98421a into master Jun 11, 2023
@Martin1887 Martin1887 deleted the fix-551 branch June 11, 2023 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strikethrough sequence missed for specific inputs

3 participants