From 31ea56084edc8ac1e27d86edfde2a562c5bd3cc0 Mon Sep 17 00:00:00 2001 From: mbrannen Date: Mon, 7 Mar 2022 23:15:55 -0700 Subject: [PATCH 1/3] updated regex sanitization -allows % -updated escape characters to \ --- src/Terminal/commands/expr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Terminal/commands/expr.ts b/src/Terminal/commands/expr.ts index d92725fd5..a4d810350 100644 --- a/src/Terminal/commands/expr.ts +++ b/src/Terminal/commands/expr.ts @@ -17,7 +17,7 @@ export function expr( const expr = args.join(""); // Sanitize the math expression - const sanitizedExpr = expr.replace(/s+/g, "").replace(/[^-()\d/*+.]/g, ""); + const sanitizedExpr = expr.replace(/s+/g, "").replace(/[^-()\d\*+.\%]/g, ""); let result; try { result = eval(sanitizedExpr); From bb6d90fb4147069330d28f0487ecf15816da5720 Mon Sep 17 00:00:00 2001 From: mbrannen Date: Mon, 7 Mar 2022 23:50:05 -0700 Subject: [PATCH 2/3] updated expression. -removed escaping and reverted back for / --- src/Terminal/commands/expr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Terminal/commands/expr.ts b/src/Terminal/commands/expr.ts index a4d810350..7791b4563 100644 --- a/src/Terminal/commands/expr.ts +++ b/src/Terminal/commands/expr.ts @@ -17,7 +17,7 @@ export function expr( const expr = args.join(""); // Sanitize the math expression - const sanitizedExpr = expr.replace(/s+/g, "").replace(/[^-()\d\*+.\%]/g, ""); + const sanitizedExpr = expr.replace(/s+/g, "").replace(/[^-()\d*/+.\%]/g, ""); let result; try { result = eval(sanitizedExpr); From 9602dbda2e206882b02846c0694426100f4db708 Mon Sep 17 00:00:00 2001 From: mbrannen <31431729+mbrannen@users.noreply.github.com> Date: Tue, 8 Mar 2022 18:02:54 -0700 Subject: [PATCH 3/3] Update src/Terminal/commands/expr.ts Updated to ApamNapat's suggestion Co-authored-by: ApamNapat --- src/Terminal/commands/expr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Terminal/commands/expr.ts b/src/Terminal/commands/expr.ts index 7791b4563..5645431e3 100644 --- a/src/Terminal/commands/expr.ts +++ b/src/Terminal/commands/expr.ts @@ -17,7 +17,7 @@ export function expr( const expr = args.join(""); // Sanitize the math expression - const sanitizedExpr = expr.replace(/s+/g, "").replace(/[^-()\d*/+.\%]/g, ""); + const sanitizedExpr = expr.replace(/s+/g, "").replace(/[^-()\d/*+.%]/g, ""); let result; try { result = eval(sanitizedExpr);