MantisBT - CMake
View Issue Details
0005999CMakeCMakepublic2007-11-02 17:552016-06-10 14:30
Brandon Van Every 
Bill Hoffman 
normalmajoralways
closedmoved 
 
 
0005999: REGEX ^ does not anchor against the original string
^ doesn't anchor against the original input string. It anchors against the string as it is processed! If replacements cause the string to have a new beginning, it anchors against the new beginning. Perl does not exhibit this behavior. I know CMake is not Perl, but Perl is a good baseline for "sanity" in regex processing. If a ^ anchor isn't respected then it renders the use of such an anchor fairly pointless.

Reproducer script anchor.cmake:

SET(sillystring "I wanna rock!")
MESSAGE("original string:")
MESSAGE("${sillystring}")
MESSAGE("expecting replacement to remove the leading 'I'. Instead we get:")
STRING(REGEX REPLACE
  "^."
  ""
  out "${sillystring}")
MESSAGE("${out}")


C:\devel\src\cbugs\anchor>cmake -P anchor.cmake
original string:
I wanna rock!
expecting replacement to remove the leading 'I'. Instead we get:


C:\devel\src\cbugs\anchor>


For comparison, a Perl script anchor.pl:

my $sillystring;
$sillystring = "I wanna rock!\n";
print "Original string:\n";
print $sillystring;
print "Expecting replacement to remove the leading 'I'. In Perl we get:\n";
$sillystring =~ s/^.//;
print $sillystring;


bvanevery@OLDFAITHFUL /c/devel/moz
$ perl anchor.pl
Original string:
I wanna rock!
Expecting replacement to remove the leading 'I'. In Perl we get:
 wanna rock!

bvanevery@OLDFAITHFUL /c/devel/moz
$
No tags attached.
Issue History
2007-11-02 17:55Brandon Van EveryNew Issue
2007-11-02 17:59Brandon Van EveryDescription Updated
2007-11-03 16:27Brandon Van EveryNote Added: 0009626
2007-12-14 20:49Bill HoffmanStatusnew => assigned
2007-12-14 20:49Bill HoffmanAssigned To => Bill Hoffman
2016-06-10 14:27Kitware RobotNote Added: 0041401
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:30Kitware RobotStatusresolved => closed

Notes
(0009626)
Brandon Van Every   
2007-11-03 16:27   
Additionally, a regex of ".$" only replaces 1 character at the end of the string. CMake's behavior is inconsistent with respect to leading and trailing anchors, proving that this is a bug and not something CMake does "on principle" out of greed.

SET(sillystring "I wanna rock!")
MESSAGE("original string:")
MESSAGE("${sillystring}")
MESSAGE("expecting replacement to remove the leading 'I'. Instead we get:")
STRING(REGEX REPLACE
  "^."
  ""
  out "${sillystring}")
MESSAGE("${out}")
MESSAGE("$ doesn't have the problem, only ^")
MESSAGE("Here we get rid of the trailing '!'")
STRING(REGEX REPLACE
  ".$"
  ""
  out "${sillystring}")
MESSAGE("${out}")

C:\devel\src\cbugs\anchor>cmake -P anchor.cmake
original string:
I wanna rock!
expecting replacement to remove the leading 'I'. Instead we get:

$ doesn't have the problem, only ^
Here we get rid of the trailing '!'
I wanna rock

C:\devel\src\cbugs\anchor>
(0041401)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.