From eef31edf5029a8e9e2f24a3bfbe5ae25de8d93f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erdem=20K=C3=B6=C5=9Fk?= Date: Mon, 11 Dec 2023 17:39:59 +0300 Subject: [PATCH] [hotfix] hotfix on mongo compare logic --- lib/logic/fuzzy.logic.ts | 29 +++++++++++++++++++++-------- package.json | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/logic/fuzzy.logic.ts b/lib/logic/fuzzy.logic.ts index 9eb9858..54d2d4b 100644 --- a/lib/logic/fuzzy.logic.ts +++ b/lib/logic/fuzzy.logic.ts @@ -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 } } diff --git a/package.json b/package.json index 9010560..cdb3538 100644 --- a/package.json +++ b/package.json @@ -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": {