Skip to content

fix: potential non-url Fixes being added to metadata #485

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/links.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ const FIX_RE = /(Close[ds]?|Fix(e[ds])?|Resolve[sd]?)\s*:\s*(\S+)/i;
const REFS_RE = /Refs?\s*:\s*(\S+)/mgi;
const REF_RE = /Refs?\s*:\s*(\S+)/i;
const PR_RE = /PR-URL\s*:\s*(\S+)/i;
const LINK_RE = /(#?\d+)|(\S+\/\S+(\/#?|\/?)\d+)/;
Copy link
Member

Choose a reason for hiding this comment

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

This matches just numbers (first clause), is that right as I don't think it's a valid GitHub Fixes value?
Also, this allows for something like some-text.../12345.

Could I suggest something like

^(#\d+|[^\s/]+\/[^\s/]+#\d+|https?:\/\/github\.com\/[^\s/]+\/[^\s/]+\/(issue|pull)\/\d+)$
     ^                ^                                                         ^
  handle       |   handle      |              handle http(s)://github.com/<any>/<any>/issue
 same-repo     |   GitHub      |              or pull/issue pr number
 shorthand     |  shorthand    |

The [^\s/] can be simplified to \w if we don't care about unicode names.

testing link https://regex101.com/r/JCwzau/1, there are a few unit-tests as well

Copy link
Member Author

@codebytere codebytere Aug 22, 2020

Choose a reason for hiding this comment

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

@lundibundi I do agree it could be more robust - i'm happy to swap to this one :D


const cheerio = require('cheerio');

/**
@@ -22,7 +24,7 @@ class LinkParser {
const result = [];
for (const item of arr) {
const m = item.match(FIX_RE);
if (!m) continue;
if (!m || !LINK_RE.test(m[3])) continue;
const fix = m[3];
const url = fix.replace(/^#/,
`${owner}/${repo}#`).replace('#', '/issues/');