Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for lack of quoting of regexp parameters in shell #142

Closed
wants to merge 2 commits into from

3 participants

James Pharaoh Randolph Tan Ian Whalen
Randolph Tan
Collaborator

Hi,

We are about to integrate your fix into the repo. In order to do that, can you sign the contributor agreement (link below)?

http://www.10gen.com/contributor

Thanks!

James Pharaoh

I have signed the agreement. I will point out that I took the RegExp more or less unchanged from an external source. I doubt this is a problem because it's not really possible to write it particularly differently and it's a tiny snippet of code. The external site is: http://80.68.89.23/2006/Jan/20/escape/. The rest of the work was entirely mine.

Ian Whalen
Collaborator

Closing as it appears that this pull request was successfully merged in commit 46bc489. Thanks a lot for your work, @jamespharaoh.

Ian Whalen IanWhalen closed this
Kyle Erf 3rf referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Esha Maharishi EshaMaharishi referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Esha Maharishi EshaMaharishi referenced this pull request from a commit in mongodbinc-interns/pubsub
Randolph Tan renctan SERVER-3702 printShardingStatus interprets database name as regular e…
…xpression

Merged pull request from: mongodb/mongo#142
Added a simple test for the pull request.


Former-commit-id: 46bc489a886d6d330a518ba8aaef05249b4798e3
9cf4f64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 5 deletions.
  1. +3 −3 shell/servers.js
  2. +5 −1 shell/utils.js
  3. +1 −1  shell/utils_sh.js
6 shell/servers.js
View
@@ -125,7 +125,7 @@ MongoRunner.toRealPath = function( path, pathOpts ){
path = path.replace( /\$dataPath/g, MongoRunner.dataPath )
path = path.replace( /\$dataDir/g, MongoRunner.dataDir )
for( key in pathOpts ){
- path = path.replace( RegExp( "\\$" + key, "g" ), pathOpts[ key ] )
+ path = path.replace( RegExp( "\\$" + RegExp.escape(key), "g" ), pathOpts[ key ] )
}
// Relative path
@@ -1050,7 +1050,7 @@ printShardingStatus = function( configDB , verbose ){
output( "\t" + tojsononeline(db,"",true) );
if (db.partitioned){
- configDB.collections.find( { _id : new RegExp( "^" + db._id + "\\." ) } ).sort( { _id : 1 } ).forEach(
+ configDB.collections.find( { _id : new RegExp( "^" + RegExp.escape(db._id) + "\\." ) } ).sort( { _id : 1 } ).forEach(
function( coll ){
if ( coll.dropped == false ){
output("\t\t" + coll._id + " chunks:");
@@ -1116,7 +1116,7 @@ printShardingSizes = function(){
output( "\t" + tojson(db,"",true) );
if (db.partitioned){
- configDB.collections.find( { _id : new RegExp( "^" + db._id + "\." ) } ).sort( { _id : 1 } ).forEach(
+ configDB.collections.find( { _id : new RegExp( "^" + RegExp.escape(db._id) + "\." ) } ).sort( { _id : 1 } ).forEach(
function( coll ){
output("\t\t" + coll._id + " chunks:");
configDB.chunks.find( { "ns" : coll._id } ).sort( { min : 1 } ).forEach(
6 shell/utils.js
View
@@ -321,7 +321,7 @@ String.prototype.startsWith = function (str){
}
String.prototype.endsWith = function (str){
- return new RegExp( str + "$" ).test( this )
+ return new RegExp( RegExp.escape(str) + "$" ).test( this )
}
Number.prototype.zeroPad = function(width) {
@@ -407,6 +407,10 @@ ISODate = function(isoDateStr){
return new Date(time);
}
+RegExp.escape = function( text ){
+ return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+}
+
RegExp.prototype.tojson = RegExp.prototype.toString;
Array.contains = function( a , x ){
2  shell/utils_sh.js
View
@@ -30,7 +30,7 @@ sh._dataFormat = function( bytes ){
}
sh._collRE = function( coll ){
- return RegExp( "^" + (coll + "").replace(/\./g, "\\.") + "-.*" )
+ return RegExp( "^" + RegExp.escape(coll + "") + "-.*" )
}
sh._pchunk = function( chunk ){
Something went wrong with that request. Please try again.