From db36c7ae9509759743aadb6556351a6c1ba5d2c6 Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 24 Apr 2021 11:22:27 +0200 Subject: [PATCH] Support URL-safe strings in scoped packages (#148) --- test/util-test.js | 16 ++++++++++++++++ util.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) 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() }) 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,