String#gsub not supported fully string pattern
Reported by Marton Kiss-Albert | July 29th, 2008 @ 05:48 PM | in 1.6.1
The gsub function not supported fully the string patterns
eg.:
var str='sky :-)';
var pat=':-)';
var rep='Smyle';
var out=str.gsub(pat,rep);
ERROR 'unmatched ) in regular expression'
The gsub function using regExp.match() function, also match() function using regular expression.
Patch:
Object.extend(String.prototype, {
gsub: function(pattern, replacement) {
var result = '', source = this, match;
replacement = arguments.callee.prepareReplacement(replacement);
// INSERTED LINE: --------------------
if(Object.isString(pattern)) pattern=pattern.replace(/([.\\+*?[\]^$(){}=!<>|:])/g,'\\$1');
// END OF INSERTION ------------------
while (source.length > 0) {
if (match = source.match(pattern)) {
result += source.slice(0, match.index);
result += String.interpret(replacement(match));
source = source.slice(match.index + match[0].length);
} else {
result += source, source = '';
}
}
return result;
},
...}
(Sorry my English)
Comments and changes to this ticket
-
John-David Dalton July 29th, 2008 @ 06:32 PM
- → Assigned user changed from to John-David Dalton
- → State changed from new to bug
-
John-David Dalton July 31st, 2008 @ 12:11 AM
- → Title changed from gsub not supported fully string pattern to String#gsub not supported fully string pattern
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
