Skip to content

Commit

Permalink
Support URL-safe strings in scoped packages (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco authored Apr 24, 2021
1 parent b772a42 commit db36c7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions test/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ test('getDownloadUrl() expands template to correct values', function (t) {
}
var url3 = util.getDownloadUrl(o3)
t.equal(url3, url2, 'scope does not matter for download url')
var o4 = {
pkg: {
name: '@scope-with.special~chars_/a-native-module',
version: 'x.y.z+beta77',
binary: {
host: 'https://foo.com',
module_name: 'a-native-module-bindings',
package_name: '{name}-{package_name}-{version}-{major}-{minor}-{patch}-{build}-{abi}-{node_abi}-{platform}-{arch}-{configuration}-{module_name}'
}
},
platform: 'coolplatform',
arch: 'futureplatform',
debug: true
}
var url4 = util.getDownloadUrl(o4)
t.equal(url4, url2, 'scope with special characters does not matter for download url')
t.end()
})

Expand Down
2 changes: 1 addition & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var crypto = require('crypto')
var expandTemplate = require('expand-template')()

function getDownloadUrl (opts) {
var pkgName = opts.pkg.name.replace(/^@\w+\//, '')
var pkgName = opts.pkg.name.replace(/^@[a-zA-Z0-9_\-.~]+\//, '')
return expandTemplate(urlTemplate(opts), {
name: pkgName,
package_name: pkgName,
Expand Down

0 comments on commit db36c7a

Please sign in to comment.