Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Fix handling of binary files when using ripgrep scanner #19403

Merged
merged 3 commits into from May 27, 2019
Merged

Conversation

rafeca
Copy link
Contributor

@rafeca rafeca commented May 24, 2019

This PR is a follow-up of #19348

By pure chance I've found an issue when handling files that have lines with binary content while testing the ripgrep scanner on the gecko-dev repository.

The main problem is found when a file has lines with non-UTF characters it returns a base64 representation of that line in the json output (to not break the JSON formatting). There's more information about it here.

Before this PR, we were not handling this scenario and the parser miserably failed 馃槄

Copy link
Contributor

@nathansobo nathansobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find! 鈿★笍

}

return Buffer.from(input.bytes, 'base64').toString()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Putting this in an else block would be more readable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just used a ternary at the end 馃榿

@@ -280,7 +292,7 @@ module.exports = class RipgrepDirectorySearcher {

if (message.type === 'begin') {
pendingEvent = {
filePath: message.data.path.text,
filePath: getText(message.data.path),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, base64 encoded paths? Awesome.

@nathansobo
Copy link
Contributor

In case anyone is wondering whether there's anything possible in these JSON objects other than text and bytes, there isn't.

@rafeca rafeca merged commit 752555b into master May 27, 2019
@rafeca rafeca deleted the fix-binary-files branch May 27, 2019 09:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants