Skip to content

Commit

Permalink
Does not bail out when capture group is empty (OctoLinker#540)
Browse files Browse the repository at this point in the history
* Does not bail out when capture group is empty

* Insert link when value is a string
  • Loading branch information
stefanbuck authored Jan 22, 2019
1 parent cbbb95b commit 883ed30
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/helper-insert-link/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ exports[`insert-link does not remove closing parentheses from commented out requ
</div>
`;

exports[`insert-link does not wrap element when capture group empty 1`] = `
<div>
foo
<span>
'
foo:
bar'
</span>
</div>
`;

exports[`insert-link returns returns an array 1`] = `
Array [
Object {
Expand Down
7 changes: 7 additions & 0 deletions packages/helper-insert-link/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ describe('insert-link', () => {
expect(helper(input, REQUIRE).el).toMatchSnapshot();
});

it('does not wrap element when capture group empty', () => {
const regex = /foo:([0-9])?/;
const input = "foo <span>'foo:bar'</span>";

expect(helper(input, regex).el).toMatchSnapshot();
});

describe('returns', () => {
it('returns an array', () => {
const input = 'foo <span>"bar"</span>';
Expand Down
8 changes: 8 additions & 0 deletions packages/helper-insert-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ function replace(portion, match) {

const matchValue = match[1];

if (matchValue === undefined) {
return {
isMatch: false,
node: text,
link: null,
};
}

if (node.textContent.includes(matchValue)) {
const el = wrapsInnerString(text, matchValue);

Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-npm-manifest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ function linkDependency(blob, key, value) {
}

function linkFile(blob, key, value) {
if (typeof value !== 'string') {
return;
}

const regex = jsonRegExValue(key, value, blob.isDiff);
return insertLink(blob, regex, this, { type: 'file' });
}
Expand Down

0 comments on commit 883ed30

Please sign in to comment.