What is the issue about
There is an error while parsing the Fix Path that ends with an array value. This error occurs when the YAML parse function tries to parse a path which is not present in YAML file and the path ends with an array value. For example spec.template.spec.containers[0].securityContext.capabilities.drop[0].
If the YAML file does not contain any value at this path spec.template.spec.containers[0].securityContext.capabilities.drop[0], the program should have returned -1 . So that no value is highlighted/marked for this path and this should not appear in problem pane.
But due a small bug in getStartIndexAcc method, the program returns a wrong Start Index, which results in wrong highlight.
Example
for path spec.template.spec.containers[0].securityContext.capabilities.drop[0], the last item is drop, if it is present in our YAML file, no issue will occur and scan will run just fine. But in case there is no drop in our YAML file, the function should have returned -1 but it does not.
Why this issue occur
There is a small condition check missing that should ensure that when handleArrayMatch is called for isLastItem, the condition should be that it should only call when startIndex is greater than -1 means that lastItem should be present in our YAML file.
startIndexAcc.tempMatch = step.match(regExpForArrayIndex);
const isLastItem = stepIndex === (steps.length - 1);
if (isLastItem && startIndexAcc.tempMatch) { // This part is where we need a change in condition
handleArrayMatch(startIndexAcc, lines, indentArray, indentArray);
}
Solution
We only need to add a condition to check if ( startIndexAcc.startIndex > -1 ), So that it does not call the handleArrayMatch for path values which does not exist in YAML file.
This is needed because for in above case we pass indentation '- ' for search term, which will be true always.
What is the issue about There is an error while parsing the
Fix Path
that ends with an array value. This error occurs when the YAML parse function tries to parse a path which is not present in YAML file and the path ends with an array value. For examplespec.template.spec.containers[0].securityContext.capabilities.drop[0]
.spec.template.spec.containers[0].securityContext.capabilities.drop[0]
, the program should havereturned -1
. So that no value is highlighted/marked for this path and this should not appear in problem pane.getStartIndexAcc
method, the program returns a wrong Start Index, which results in wrong highlight.Example for path
spec.template.spec.containers[0].securityContext.capabilities.drop[0]
, the last item isdrop
, if it is present in our YAML file, no issue will occur and scan will run just fine. But in case there is nodrop
in our YAML file, the function should have returned -1 but it does not.Why this issue occur There is a small condition check missing that should ensure that when
handleArrayMatch
is called forisLastItem
, the condition should be that it should only call whenstartIndex
is greater than-1
means thatlastItem
should be present in our YAML file.Solution We only need to add a condition to check
if ( startIndexAcc.startIndex > -1 )
, So that it does not call thehandleArrayMatch
for path values which does not exist in YAML file.indentation '- '
for search term, which will be true always.