File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ Object.extend(String.prototype, (function() {
38
38
var template = new Template ( replacement ) ;
39
39
return function ( match ) { return template . evaluate ( match ) } ;
40
40
}
41
+
42
+ // In some versions of Chrome, an empty RegExp has "(?:)" as a `source`
43
+ // property instead of an empty string.
44
+ function isNonEmptyRegExp ( regexp ) {
45
+ return regexp . source && regexp . source !== '(?:)' ;
46
+ }
47
+
41
48
42
49
/**
43
50
* String#gsub(pattern, replacement) -> String
@@ -93,8 +100,8 @@ Object.extend(String.prototype, (function() {
93
100
94
101
if ( Object . isString ( pattern ) )
95
102
pattern = RegExp . escape ( pattern ) ;
96
-
97
- if ( ! ( pattern . length || pattern . source ) ) {
103
+
104
+ if ( ! ( pattern . length || isNonEmptyRegExp ( pattern ) ) ) {
98
105
replacement = replacement ( '' ) ;
99
106
return replacement + source . split ( '' ) . join ( replacement ) + replacement ;
100
107
}
Original file line number Diff line number Diff line change @@ -46,9 +46,9 @@ new Test.Unit.Runner({
46
46
'ウィメンズ2007\nクルーズコレクション' . gsub ( '\n' , '<br/>' ) ) ;
47
47
48
48
this . assertEqual ( 'barfbarobarobar barbbarobarobar barbbarobarzbar' ,
49
- source . gsub ( '' , 'bar' ) ) ;
49
+ source . gsub ( '' , 'bar' ) , 'empty string' ) ;
50
50
this . assertEqual ( 'barfbarobarobar barbbarobarobar barbbarobarzbar' ,
51
- source . gsub ( new RegExp ( '' ) , 'bar' ) ) ;
51
+ source . gsub ( new RegExp ( '' ) , 'bar' ) , 'empty regexp' ) ;
52
52
} ,
53
53
54
54
testGsubWithReplacementTemplateString : function ( ) {
You can’t perform that action at this time.
0 commit comments