[Security Solution] Fix code scanning alert (#198142)

Fixes
[https://github.com/elastic/kibana/security/code-scanning/365](https://github.com/elastic/kibana/security/code-scanning/365)

## Summary

To fix the problem, we need to ensure that both double quotes and
backslashes are properly escaped in the `escapeValue` function. This can
be achieved by using a regular expression that replaces both characters
globally. Specifically, we should replace backslashes with double
backslashes (`\\`) and double quotes with escaped double quotes (`\"`).

- Update the `escapeValue` function to use a regular expression that
handles both double quotes and backslashes.
- Ensure that the regular expression has the global flag (`g`) to
replace all occurrences of the characters.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
Agustina Nahir Ruidiaz 2024-10-30 15:38:54 +01:00 committed by GitHub
parent fdd5e0be75
commit b9a5d6a46d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,7 +33,7 @@ const COPY_TO_CLIPBOARD_SUCCESS = i18n.translate(
}
);
const escapeValue = (value: string) => value.replace(/"/g, '\\"');
const escapeValue = (value: string) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
export const createCopyToClipboardActionFactory = createCellActionFactory(
({ notifications }: { notifications: NotificationsStart }) => ({