normalize-url 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +9 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -48,9 +48,16 @@ module.exports = (urlString, opts) => {
48
48
  urlObj.hash = '';
49
49
  }
50
50
 
51
- // Remove duplicate slashes
51
+ // Remove duplicate slashes if not preceded by a protocol
52
52
  if (urlObj.pathname) {
53
- urlObj.pathname = urlObj.pathname.replace(/\/{2,}/g, '/');
53
+ // TODO: Use the following instead when targeting Node.js 10
54
+ // `urlObj.pathname = urlObj.pathname.replace(/(?<!https?:)\/{2,}/g, '/');`
55
+ urlObj.pathname = urlObj.pathname.replace(/((?![https?:]).)\/{2,}/g, (_, p1) => {
56
+ if (/^(?!\/)/g.test(p1)) {
57
+ return `${p1}/`;
58
+ }
59
+ return '/';
60
+ });
54
61
  }
55
62
 
56
63
  // Decode URI octets
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "normalize-url",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Normalize a URL",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/normalize-url",