https://bugs.exim.org/show_bug.cgi?id=2187
Bug ID: 2187 Summary: garbled output in multiline mode Product: PCRE Version: 10.30 (PCRE2) Hardware: x86-64 OS: Linux Status: NEW Severity: bug Priority: medium Component: Code Assignee: p...@hermes.cam.ac.uk Reporter: glyphi...@gmail.com CC: pcre-dev@exim.org Hello again, The affected software is pcregrep (8.41) and pcre2grep (10.30) on Linux (Gentoo). Noticed some issues w/ pcre2grep output while doing multiline greps. It seems to occur when there are 2 matches on 1 line, the 2nd match of which extends onto a 2nd line. (In contrast, it works ok when a match goes from line 1 to line 2, and there's a 2nd match on line 2.) Run these commands to reproduce. (You can also add options like -H or -n to the grep commands to make the output clearer -- it doesn't affect the results.) -- mkdir test cd test echo "start end" > 1-line-1-match.txt echo -e "start\nend" > 2-lines-1-match.txt echo -e "start\nend start end" > 2-lines-ending-with-2-matches.txt echo -e "start end start\nend" > 2-lines-starting-with-2-matches.txt pcre2grep -M --color -e 'start[\s]+end' 1-line-1-match.txt pcre2grep -M --color -e 'start[\s]+end' 2-lines-1-match.txt pcre2grep -M --color -e 'start[\s]+end' 2-lines-ending-with-2-matches.txt pcre2grep -M -e 'start[\s]+end' 2-lines-ending-with-2-matches.txt pcre2grep -M -e 'start[\s]+end' 2-lines-starting-with-2-matches.txt pcre2grep -M --color -e 'start[\s]+end' 2-lines-starting-with-2-matches.txt -- The grep output looks like this: -- $ pcre2grep -M --color -e 'start[\s]+end' 1-line-1-match.txt start end $ pcre2grep -M --color -e 'start[\s]+end' 2-lines-1-match.txt start end $ pcre2grep -M --color -e 'start[\s]+end' 2-lines-ending-with-2-matches.txt start end start end $ pcre2grep -M -e 'start[\s]+end' 2-lines-ending-with-2-matches.txt start end start end $ pcre2grep -M -e 'start[\s]+end' 2-lines-starting-with-2-matches.txt start end start $ pcre2grep -M --color -e 'start[\s]+end' 2-lines-starting-with-2-matches.txt start end start end$ -- Commands 1 thru 4 work fine, printing the matching text -- in color when specified, and across multiple lines where appropriate. Command 5 (2-lines-starting-with-2-matches.txt, no --color) doesn't work. It only prints the 1st line, when there should be a 2nd match, spread across lines 1-2. Command 6 (2-lines-starting-with-2-matches.txt, w/ --color) also doesn't work. It does print lines 1-2, and the 2 separate matches are colored correctly. However, after the 2nd match, it fails to print a newline, so the next terminal prompt appears on the same line. Also, it fails to print the ANSI escape code to end the coloring -- my terminal ends up w/ a red cursor. The lack of a newline is especially jarring when the -H or -M commands are being used -- the info just gets printed on the same line as the colored text. ... One more thing, which may or may not merit a different bug report. Run: -- echo -e "start end start\n\nend" > 3-lines.txt pcre2grep -Mn -A 2 --color -e 'start[\s]+end' 3-lines.txt -- Grep output is: -- $ pcre2grep -Mn -A 2 --color -e 'start[\s]+end' 3-lines.txt 1:start end start end2- 3-end -- In addition to not printing a newline after the multiline colored matching text, it starts printing context lines that repeat lines it already printed. -- You are receiving this mail because: You are on the CC list for the bug. -- ## List details at https://lists.exim.org/mailman/listinfo/pcre-dev