2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-13 12:22:17 +00:00

Handle empty matches in regex.replace. Fixes #421.

This commit is contained in:
Steven Watanabe
2019-04-03 11:28:54 -06:00
parent 43fde46778
commit 304dcb656e
2 changed files with 8 additions and 1 deletions

View File

@@ -108,7 +108,13 @@ LIST * regex_replace( FRAME * frame, int flags )
{
string_append_range( buf, pos, re->startp[ 0 ] );
string_append( buf, object_str( replacement ) );
pos = re->endp[ 0 ];
/* Handle empty matches */
if ( *pos == '\0' )
break;
else if ( pos == re->endp[ 0 ] )
++pos;
else
pos = re->endp[ 0 ];
}
string_append( buf, pos );

View File

@@ -198,6 +198,7 @@ rule __test__ ( )
assert.result " string string" : replace " string string" " " " " ;
assert.result "string  string" : replace "string string" " " " " ;
assert.result "-" : replace "&" "&" "-" ;
assert.result "x" : replace "" "" "x" ;
assert.result "-" "a-b" : replace-list "&" "a&b" : "&" : "-" ;
}