git.iko.soy/typeable/remark-validate-links
on main help sign in
Fix support for URLs containing a query string

Closes GH-37. Co-authored-by: Titus Wormer <tituswormer@gmail.com>

commit45f58f9f4e6a6fb5f7b6f6a715202395791d4a6b authorJonathan Haines <jonno.haines@gmail.com> dateMon 18 Mar 2019, 12:12 (8 years ago) parentdc2de9f
3 files changed+32
index.js+5 test/fixtures/query-params.md+7 test/index.js+20
index.js+5
@@ -31,6 +31,7 @@ var fileRuleId = 'missing-file'
3131cliCompleter.pluginId = sourceId
3232
3333var parse = url.parse
34+var format = url.format
3435
3536var viewPaths = {
3637 github: 'blob',
@@ -296,6 +297,10 @@ function gatherReferences(file, tree, info, fileSet) {
296297
297298 uri = parse(link)
298299
300+ // Drop `?search`
301+ uri.search = ''
302+ link = format(uri)
303+
299304 if (!fileSet && (uri.hostname || uri.pathname)) {
300305 return
301306 }
test/fixtures/query-params.mdnew file+7
@@ -0,0 +1,7 @@
1+# Query params
2+
3+Link to relative heading ![link](?foo=bar#query-params)
4+
5+Link to an ![image](./examples/image.jpg?foo=bar)
6+
7+And a file [link](./examples/github.md?foo=bar).
test/index.js+20
@@ -524,5 +524,25 @@ test('remark-validate-links', function(t) {
524524 }, st.error)
525525 })
526526
527+ t.test('should support query parameters', function(st) {
528+ st.plan(1)
529+
530+ execa(bin, [
531+ '--no-config',
532+ '--no-ignore',
533+ '--use',
534+ '../..=repository:"wooorm/test"',
535+ '--use',
536+ '../sort',
537+ 'query-params.md'
538+ ]).then(function(result) {
539+ st.equal(
540+ strip(result.stderr),
541+ 'query-params.md: no issues found',
542+ 'should report'
543+ )
544+ }, st.error)
545+ })
546+
527547 t.end()
528548})