Bug 323525

Summary: Symbol viewer's perl parser can incorrectly identify lines as the start of a comment
Product: [Applications] kate Reporter: John Schroeder <schroederjohn88+kdebugs>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: schroederjohn88+kdebugs
Priority: NOR    
Version: Git   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In: 4.11.1
Sentry Crash Report:
Attachments: Sample test case
Proposed patch

Description John Schroeder 2013-08-15 04:36:01 UTC
The current implementation of symbol viewer's perl parser can incorrectly identify lines lines that match '^\s=' as the beginning of a comment.

Reproducible: Always

Steps to Reproduce:
1. Open create a perl file that has code like:
my $foo
= 'bar';
2. Observe that symbol viewer's perl parser interprets the line "= 'bar';" as the start of a comment.
Actual Results:  
This should not be interpreted as a comment.  It is a multi-line statement with an assignment operator beginning the second line.

Perl's documentation at:
http://perldoc.perl.org/perlpodspec.html

Specifies that a comment begins with a line that "matches <m/\A=[a-zA-Z]/>".  In other words, the line must begin with a '=' character followed immediately by an alpha character.

Expected Results:  
Symbol viewer's perl parser should only identify lines as the beginning of a comment if they match perl's documented pattern that identifies the start of a comment.
Comment 1 John Schroeder 2013-08-15 04:37:27 UTC
Created attachment 81714 [details]
Sample test case
Comment 2 John Schroeder 2013-08-15 04:38:04 UTC
I have attached a sample test case that highlights the pitfalls of the current implementation.
Comment 3 John Schroeder 2013-08-15 04:39:34 UTC
Created attachment 81715 [details]
Proposed patch
Comment 4 John Schroeder 2013-08-15 04:41:42 UTC
And finally, I've attached a patch that addresses these shortcomings by not trimming the line being analyzed until after comment detection has been attempted and by modifying the regular expression used to identify the beginning of a comment.
Comment 5 Dominik Haumann 2013-08-15 07:21:00 UTC
Git commit 94719b9790671b27a80698ee55439f9a59db4b38 by Dominik Haumann.
Committed on 15/08/2013 at 07:20.
Pushed by dhaumann into branch 'master'.

symbol viewer: fix perl parsing comments

problem was:
my $foo
  = 'bar';

Thanks to John Schroeder for the patch!

FIXED-IN: 4.11.1

M  +4    -3    addons/kate/symbolviewer/perl_parser.cpp

http://commits.kde.org/kate/94719b9790671b27a80698ee55439f9a59db4b38
Comment 6 Dominik Haumann 2013-08-15 07:21:28 UTC
Git commit dc74d823340c75a4d06b9b3da2c40dff04852af9 by Dominik Haumann.
Committed on 15/08/2013 at 07:20.
Pushed by dhaumann into branch 'KDE/4.11'.

symbol viewer: fix perl parsing comments

problem was:
my $foo
  = 'bar';

Thanks to John Schroeder for the patch!

FIXED-IN: 4.11.1

M  +4    -3    addons/kate/symbolviewer/perl_parser.cpp

http://commits.kde.org/kate/dc74d823340c75a4d06b9b3da2c40dff04852af9
Comment 7 Dominik Haumann 2013-08-15 07:23:46 UTC
John, if you want, you can also ask for commit access http://sysadmin.kde.org/tickets/ so that you can commit yourself :-)