From e7a3d146df0b15c500f9bd85fa7b4b509bad9c39 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 6 Jun 2024 01:26:33 +0530 Subject: [PATCH] feat: remove spaces after \HEX escapes that are not followed by a hex digit --- server/src/workflow-management/selector.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/src/workflow-management/selector.ts b/server/src/workflow-management/selector.ts index c211669b..4644a09a 100644 --- a/server/src/workflow-management/selector.ts +++ b/server/src/workflow-management/selector.ts @@ -537,6 +537,23 @@ export const getSelectors = async (page: Page, coordinates: Coordinates) => { output = '\\3' + firstChar + ' ' + output.slice(1); } } + + // Remove spaces after `\HEX` escapes that are not followed by a hex digit, + // since they’re redundant. Note that this is only possible if the escape + // sequence isn’t preceded by an odd number of backslashes. + output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) { + if ($1 && $1.length % 2) { + // It’s not safe to remove the space, so don’t. + return $0; + } + // Strip the space. + return ($1 || '') + $2; + }); + + if (!isIdentifier && options.wrap) { + return quote + output + quote; + } + return output; }