Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fnematch. #213

Closed
wants to merge 1 commit into from
Closed

Fix fnematch. #213

wants to merge 1 commit into from

Conversation

arnoldrobbins
Copy link
Collaborator

Use sane code after finding the end of the match to put back the last rune read and terminate the buffer. Fixes #212.

@millert
Copy link
Contributor

millert commented Nov 15, 2023

Thanks @arnoldrobbins for this. BTW, you don't really need a new loop variable for this, you could just operate directly on r.len since you are headed for return regardless.

@mpinjr mpinjr mentioned this pull request Nov 15, 2023
bob-beck pushed a commit to openbsd/src that referenced this pull request Nov 15, 2023
@mpinjr
Copy link
Contributor

mpinjr commented Nov 16, 2023

It's incorrect to assume that there will be only one rune's worth of bytes to put back. If the automaton went looking for a longer match, failed to find it, and settled for a shorter one, there could be much more after the match.

$ printf aaaZZZbbb | ./correct.out '{print} END {print NR}' RS='ZZZ(bbbb)?'
aaa
bbb
2
$ printf aaaZZZbbb | ./broken.out '{print} END {print NR}' RS='ZZZ(bbbb)?'
aaa
1

@arnoldrobbins
Copy link
Collaborator Author

@mpinjr I see. If your PR handles this then I'm OK with going with it. @plan9 You should probably take his PR and close mine.

@plan9 plan9 closed this Nov 20, 2023
@plan9 plan9 deleted the fix-fnematch branch November 20, 2023 18:48
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.

Extraneous output when RS is a regex
4 participants