Merge pull request #19618 from atom/fix-empty-result

Fix issue when ripgrep returns matches that are empty
This commit is contained in:
Rafael Oleza
2019-07-01 14:19:22 +02:00
committed by GitHub
2 changed files with 29 additions and 1 deletions

View File

@@ -2512,6 +2512,34 @@ describe('Workspace', () => {
});
if (ripgrep) {
it('returns empty text matches', async () => {
const results = [];
await scan(
/^\s{0}/,
{
paths: [`oh-git`]
},
result => results.push(result)
);
expect(results.length).toBe(1);
const { filePath, matches } = results[0];
expect(filePath).toBe(
atom.project
.getDirectories()[0]
.resolve(path.join('a-dir', 'oh-git'))
);
expect(matches).toHaveLength(1);
expect(matches[0]).toEqual({
matchText: '',
lineText: 'bbb aaaa',
lineTextOffset: 0,
range: [[0, 0], [0, 0]],
leadingContextLines: [],
trailingContextLines: []
});
});
describe('newlines on regexps', async () => {
it('returns multiline results from regexps', async () => {
const results = [];

View File

@@ -157,7 +157,7 @@ function processSubmatch(submatch, lineText, offsetRow) {
}
function getText(input) {
return input.text
return 'text' in input
? input.text
: Buffer.from(input.bytes, 'base64').toString();
}