Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 61217 - fixheadtails.eclass do_sed_fix() has a problematic regex
Summary: fixheadtails.eclass do_sed_fix() has a problematic regex
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Ciaran McCreesh
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-21 20:54 UTC by Bob Black
Modified: 2005-10-25 17:44 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Black 2004-08-21 20:54:44 UTC
There is a function called do_sed_fix (called by ht_fix_all) in fixheadtails.eclass that attempts to replace any head (or tail) 
instance of "head -num_of_lines" with "head -n num_of_lines" 

Unfortunately the way the regex match is specified if the file already 
has the argument of the form "head -n num_lines" it will change it to 
"head -n n num_lines" which is not valid. (Technically it will break 
any argument since it matches on -.*)

---
do_sed_fix() {
        sed -i \
                -e 's/head -\(.*\)/head -n \1/' \
                -e 's/tail \([-+]\)\(.*\)/tail -n \1\2/' ${1} || \
                        die "sed ${1} failed"
}
--

I'm not a regular expression master but i believe the regexes should be 
restricted to only matching -[:digit:]*  Maybe something like:

s/\(head .*\)-\([0-9]*\)/\1-n \2/

s/\(tail .*[-+]\)\([0-9]*\)/\1-n \2\3/



Reproducible: Always
Steps to Reproduce:
1. have file with head -n 11
2. run ht_fix_file on file


Actual Results:  
Changed head arguments to 
head -n n 11

Expected Results:  
left already correct arguments alone

I realize if the upstream fixes their files to have the "new" argument 
format then ht_fix_file should no longer be run on them.....
Comment 1 Seemant Kulleen (RETIRED) gentoo-dev 2004-08-21 21:07:57 UTC
sending to our regex master
Comment 2 Jakub Moc (RETIRED) gentoo-dev 2005-10-25 17:44:08 UTC
Seems fixed, closing a stale bug.