Skip to content

Commit

Permalink
Fix support for URLs containing a query string
Browse files Browse the repository at this point in the history
Closes GH-37.

Co-authored-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
BarryThePenguin and wooorm committed Mar 18, 2019
1 parent dc2de9f commit 45f58f9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var fileRuleId = 'missing-file'
cliCompleter.pluginId = sourceId

var parse = url.parse
var format = url.format

var viewPaths = {
github: 'blob',
Expand Down Expand Up @@ -296,6 +297,10 @@ function gatherReferences(file, tree, info, fileSet) {

uri = parse(link)

// Drop `?search`
uri.search = ''
link = format(uri)

if (!fileSet && (uri.hostname || uri.pathname)) {
return
}
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/query-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Query params

Link to relative heading ![link](?foo=bar#query-params)

Link to an ![image](./examples/image.jpg?foo=bar)

And a file [link](./examples/github.md?foo=bar).
20 changes: 20 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,25 @@ test('remark-validate-links', function(t) {
}, st.error)
})

t.test('should support query parameters', function(st) {
st.plan(1)

execa(bin, [
'--no-config',
'--no-ignore',
'--use',
'../..=repository:"wooorm/test"',
'--use',
'../sort',
'query-params.md'
]).then(function(result) {
st.equal(
strip(result.stderr),
'query-params.md: no issues found',
'should report'
)
}, st.error)
})

t.end()
})

0 comments on commit 45f58f9

Please sign in to comment.