[SERVER-48064] two_phase_drops.js pendingDropRegex is not robust to similar names Created: 08/May/20  Updated: 29/Oct/23  Resolved: 12/May/20

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Bug Priority: Major - P3
Reporter: Judah Schvimer Assignee: Judah Schvimer
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Repl 2020-05-18
Participants:
Linked BF Score: 48

 Description   

In this example, I would expect the "find" function to return the other collection.

MongoDB shell version v4.4.0-rc3
> collName = "testcoll"
testcoll
> a= new RegExp("system\.drop\..*\." + collName + "$");
/system.drop..*.testcoll$/
> b = ["system.drop.1588746254i1t1.r_testcoll", "system.drop.1588746258i5t1.testcoll"]
[
	"system.drop.1588746254i1t1.r_testcoll",
	"system.drop.1588746258i5t1.testcoll"
]
> b.find(c => a.test(c))
system.drop.1588746254i1t1.r_testcoll



 Comments   
Comment by Githook User [ 12/May/20 ]

Author:

{'name': 'Judah Schvimer', 'email': 'judah@mongodb.com', 'username': 'judahschvimer'}

Message: SERVER-48064 properly escape in pendingDropRegex
Branch: master
https://github.com/mongodb/mongo/commit/14bb6a661fc7a8b693613203693b8232c6f91944

Comment by William Schultz (Inactive) [ 08/May/20 ]

I guess this is an escaping issue. It looks like "\." doesn't properly ensure any of the dot characters are treated literally:

 
// Single escaped.
> a = new RegExp("system\.drop\..*\." + "test" + "$");
/system.drop..*.test$/
> a.test("system.drop.1588746254i1t1.r_test")
true
> a.test("system.drop.1588746254i1t1.test")
true
> a.test("system_drop_1588746254i1t1.test")
true
 
// Double escaped.
> a = new RegExp("system\\.drop\\..*\\." + "test" + "$");
/system\.drop\..*\.test$/
> a.test("system_drop_1588746254i1t1.test")
false
> a.test("system.drop.1588746254i1t1.r_test")
false
> a.test("system.drop.1588746254i1t1.test")
true

Apparently you need a double backslash to escape literals when using the RegExp constructor (1, 2). Guess I missed this when I first wrote it

Generated at Thu Feb 08 05:16:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.