Skip to content

Commit

Permalink
[hotfix] hotfix on mongo compare logic
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemkosk committed Dec 11, 2023
1 parent 9f85ed9 commit eef31ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 21 additions & 8 deletions lib/logic/fuzzy.logic.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export default class MongoDBURIComparerLogic {
static compareURIs (uri1: string, uri2: string): boolean {
const userPassRegEx = /\/\/(.*):(.*)@/
const match1 = uri1.match(userPassRegEx)
const match2 = uri2.match(userPassRegEx)
const URL_REGEXP = /^(mongodb\+srv:\/\/)([^:]+):([^@]+)@([^/]+)\/(.+)$/

if ((match1 != null) && (match2 != null) && match1[1] !== match2[1]) return false
if ((match1 != null) && (match2 != null) && match1[2] !== match2[2]) return false
const match1 = uri1.match(URL_REGEXP)
const match2 = uri2.match(URL_REGEXP)

const uri1WithoutUserInfo = uri1.replace(userPassRegEx, '//')
const uri2WithoutUserInfo = uri2.replace(userPassRegEx, '//')
if (!match1 || !match2) {
return false
}

return uri1WithoutUserInfo === uri2WithoutUserInfo
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [, protocol1, user1, pass1, host1, path1] = match1
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [, protocol2, user2, pass2, host2, path2] = match2

if (protocol1 !== protocol2 || path1 !== path2) {
return false
}

if (user1 !== user2 && pass1 !== pass2) {
return false
}

return true
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "envolve",
"version": "1.1.8",
"version": "1.1.9",
"description": "Envolve CLI is a powerful tool for managing environment variables in your projects. It allows you to easily create, update, compare, and sync environment files across different services.",
"main": "index.ts",
"scripts": {
Expand Down

0 comments on commit eef31ed

Please sign in to comment.