File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,8 @@ Object.extend(String.prototype, (function() {
100
100
}
101
101
102
102
while ( source . length > 0 ) {
103
- if ( match = source . match ( pattern ) ) {
103
+ match = source . match ( pattern )
104
+ if ( match && match [ 0 ] . length > 0 ) {
104
105
result += source . slice ( 0 , match . index ) ;
105
106
result += String . interpret ( replacement ( match ) ) ;
106
107
source = source . slice ( match . index + match [ 0 ] . length ) ;
Original file line number Diff line number Diff line change @@ -66,7 +66,6 @@ new Test.Unit.Runner({
66
66
67
67
testGsubWithTroublesomeCharacters : function ( ) {
68
68
this . assertEqual ( 'ab' , 'a|b' . gsub ( '|' , '' ) ) ;
69
- //'ab'.gsub('', ''); // freeze
70
69
this . assertEqual ( 'ab' , 'ab(?:)' . gsub ( '(?:)' , '' ) ) ;
71
70
this . assertEqual ( 'ab' , 'ab()' . gsub ( '()' , '' ) ) ;
72
71
this . assertEqual ( 'ab' , 'ab' . gsub ( '^' , '' ) ) ;
@@ -77,6 +76,12 @@ new Test.Unit.Runner({
77
76
this . assertEqual ( 'ab' , 'a.b' . gsub ( '.' , '' ) ) ;
78
77
} ,
79
78
79
+ testGsubWithZeroLengthMatch : function ( ) {
80
+ this . assertEqual ( 'ab' , 'ab' . gsub ( '' , '' ) ) ;
81
+ this . assertEqual ( 'a' , 'a' . gsub ( / b * / , 'c' ) ) ;
82
+ this . assertEqual ( 'abc' , 'abc' . gsub ( / b { 0 } / , '' ) ) ;
83
+ } ,
84
+
80
85
testSubWithReplacementFunction : function ( ) {
81
86
var source = 'foo boo boz' ;
82
87
You can’t perform that action at this time.
0 commit comments