From 42b2c3ab852dc90d4090a1d53032c605ad3271b3 Mon Sep 17 00:00:00 2001
From: Ildar Kamalov <ik@adguard.com>
Date: Mon, 16 Aug 2021 17:36:44 +0300
Subject: [PATCH] Pull request: 3201 use backslash to escape quotes in the
 client name

Closes #3201

Squashed commit of the following:

commit 43d2b967a4d13ff4556b2d9a7d6281b2a8be0895
Merge: 36eeb1bc 784bc318
Author: Ildar Kamalov <ik@adguard.com>
Date:   Mon Aug 16 17:29:06 2021 +0300

    Merge branch 'master' into 3201-escape-quotes

commit 36eeb1bc9862181a1cc3108300c6a12a9d913057
Author: Ildar Kamalov <ik@adguard.com>
Date:   Mon Aug 16 15:56:15 2021 +0300

    client: multiple escape

commit e7c19ddb1a5041447d9612783415ba21fcad802e
Author: Ildar Kamalov <ik@adguard.com>
Date:   Mon Aug 16 12:04:43 2021 +0300

    client: use backslash to escape quotes in the client name
---
 client/src/actions/index.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/client/src/actions/index.js b/client/src/actions/index.js
index 4f4b6b20..c634d630 100644
--- a/client/src/actions/index.js
+++ b/client/src/actions/index.js
@@ -638,7 +638,11 @@ export const toggleBlocking = (
 };
 
 export const toggleBlockingForClient = (type, domain, client) => {
-    const baseRule = `||${domain}^$client='${client.replace(/'/g, '/\'')}'`;
+    const escapedClientName = client.replace(/'/g, '\\\'')
+        .replace(/"/g, '\\"')
+        .replace(/,/g, '\\,')
+        .replace(/\|/g, '\\|');
+    const baseRule = `||${domain}^$client='${escapedClientName}'`;
     const baseUnblocking = `@@${baseRule}`;
 
     return toggleBlocking(type, domain, baseRule, baseUnblocking);