-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
services/git:bugfix - error git diff breaking parse and invalid filepath #838
Conversation
259fe2b
to
311c7ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a new test case on git to assert that this bug will not occur again?
311c7ca
to
073cde2
Compare
Done! |
Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
073cde2
to
a650257
Compare
func (g *Git) getCleanOutput(output []byte) []byte { | ||
// Output from git log contains the diff changes | ||
// so we need to extract only the json output data. | ||
if idx := bytes.LastIndex(output, []byte("}")); idx >= 0 { | ||
return bytes.ReplaceAll(output[:idx+1], []byte("^^^^^"), []byte(`"`)) | ||
} | ||
logger.LogWarn(fmt.Sprintf("Could not to clean git blame output: %s", output)) | ||
return []byte("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a closer look at the code and saw this function with some unnecessary stuff. Changed to just relace the carets.
…ath (#838) Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
Signed-off-by: Nathan Martins nathan.martins@zup.com.br
- What I did
Changing function that removes default src/ horusec folder from filepath to prevent it being reported as
/hcl/example1/main.tf
, which will be looked up from root and break git blame function. Now it will return the correted pathlike this
hcl/example1/main.tf
Added flag
--no-patch
into git blame function to avoid diff info. Without it, in some cases will return extra information and break the json parse. Following the example of the output that results in error.- How to verify it
- Description for the changelog