From 393769f152b83303fcd6217a84718300f6de9aa4 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Wed, 27 Nov 2024 11:44:39 -0500 Subject: [PATCH] Accounted for last character being a newline when checking for EOS (we can be at the second-last character if the last one is a newline --- nfa.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nfa.go b/nfa.go index df9dbac..5566579 100644 --- a/nfa.go +++ b/nfa.go @@ -90,7 +90,8 @@ func (s State) checkAssertion(str []rune, idx int) bool { return idx == 0 } if s.assert == EOS { - return idx == len(str) + // Index is at the end of the string, or it points to the last character which is a newline + return idx == len(str) || (idx == len(str)-1 && str[len(str)-1] == '\n') } if s.assert == WBOUND { return isWordBoundary(str, idx)