beyondgrep/ack1

smart-case not disabled by [:upper:]

adavies42 opened this issue · 1 comments

smart-case does not consider [:upper:] as a pattern containing upper case. given that perl applies the (?i) modifier to it correctly, IMAO it should.

(i'll note that it also doesn't consider any of the unicode ways to specify uppercase (i found 3 syntaxes for 3 different properties in a quick search), but since perl doesn't seem to apply (?i) to those, it doesn't really matter.)

example and suggested patch follow

$ cat foo.txt
abc
ABC
aBc
$ ack --version
ack 1.96
Running under Perl 5.8.8 at /usr/bin/perl

Copyright 2005-2011 Andy Lester.

This program is free software.  You may modify or distribute it
under the terms of the Artistic License v2.0.
$ ack --noenv --text --smart-case '[A-Z]'
foo.txt
2:ABC
3:aBc
$ ack --noenv --text --smart-case '[[:upper:]]'
foo.txt
1:abc
2:ABC
3:aBc
$ cat patch
--- ack 2011-11-08 09:03:01.000000000 -0500
+++ ack.1   2011-12-19 12:02:07.000000000 -0500
@@ -1662,7 +1662,7 @@
         $str = "$str\\b" if $str =~ /\w$/;
     }

-    my $regex_is_lc = $str eq lc $str;
+    my $regex_is_lc = $str eq lc $str && $str !~ /\Q[:upper:]/i;
     if ( $opt->{i} || ($opt->{smart_case} && $regex_is_lc) ) {
         $str = "(?i)$str";
     }
$ ~/bin/ack.1 --noenv --text --smart-case '[[:upper:]]'
foo.txt
2:ABC
3:aBc

Migrated to ack2.