From 11a4e2dfc59323dfd19058c03e2cab62a1163f40 Mon Sep 17 00:00:00 2001 From: Marco Crespi Date: Wed, 21 Apr 2021 13:08:55 +0200 Subject: [PATCH 1/2] fix: Support URL-safe strings in scoped packages --- util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util.js b/util.js index 864ffc5..102a543 100644 --- a/util.js +++ b/util.js @@ -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, From 717eb6a36bc1551c282d689067f9b11753fde3f7 Mon Sep 17 00:00:00 2001 From: Marco Crespi Date: Wed, 21 Apr 2021 13:59:26 +0200 Subject: [PATCH 2/2] chore: Add test for special scoped packages --- test/util-test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/util-test.js b/test/util-test.js index 13c6d50..90d17c7 100644 --- a/test/util-test.js +++ b/test/util-test.js @@ -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() })