mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
[Console] Fix code scanning alert (#194700)
This commit is contained in:
parent
c0e2d95050
commit
3dbb7da016
1 changed files with 21 additions and 2 deletions
|
@ -54,9 +54,28 @@ export function formatRequestBodyDoc(data: string[], indent: boolean) {
|
|||
};
|
||||
}
|
||||
|
||||
// Regular expression to match different types of comments:
|
||||
// - Block comments, single and multiline (/* ... */)
|
||||
// - Single-line comments (// ...)
|
||||
// - Hash comments (# ...)
|
||||
export function hasComments(data: string) {
|
||||
// matches single line and multiline comments
|
||||
const re = /(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(\/\/.*)|(#.*)/;
|
||||
/*
|
||||
1. (\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\/)
|
||||
- (\/\*): Matches the start of a block comment
|
||||
- [^*]*: Matches any number of characters that are NOT an asterisk (*), to avoid prematurely closing the comment.
|
||||
- \*+: Matches one or more asterisks (*), which is part of the block comment closing syntax.
|
||||
- (?:[^/*][^*]*\*+)*: This non-capturing group ensures that any characters between asterisks and slashes are correctly matched and prevents mismatching on nested or unclosed comments.
|
||||
- \*\/: Matches the closing of a block comment
|
||||
|
||||
2. (\/\/.*)
|
||||
- Matches single-line comments starting with '//'.
|
||||
- .*: Matches any characters that follow until the end of the line.
|
||||
|
||||
3. (#.*)
|
||||
- Matches single-line comments starting with a hash (#).
|
||||
- .*: Matches any characters that follow until the end of the line.
|
||||
*/
|
||||
const re = /(\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\/)|(\/\/.*)|(#.*)/;
|
||||
return re.test(data);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue