@@ -21,6 +21,7 @@ SOFTWARE.
2121*/
2222'use strict'
2323
24+ const { decodeURIComponent } = require ( './decode' )
2425const { isObject, recursiveFreeze } = require ( './objects' )
2526const { isBlank, isNonEmptyString, trimLeadingSlashes } = require ( './strings' )
2627
@@ -172,10 +173,11 @@ class PackageURL {
172173
173174 const { pathname } = url
174175 const firstSlashIndex = pathname . indexOf ( '/' )
175- const rawType =
176+ const rawType = decodeURIComponent (
176177 firstSlashIndex === - 1
177178 ? pathname
178179 : pathname . slice ( 0 , firstSlashIndex )
180+ )
179181 if ( firstSlashIndex < 1 ) {
180182 return [
181183 rawType ,
@@ -204,20 +206,24 @@ class PackageURL {
204206 )
205207 if ( atSignIndex !== - 1 ) {
206208 // Split the remainder once from right on '@'.
207- rawVersion = pathname . slice ( atSignIndex + 1 )
209+ rawVersion = decodeURIComponent ( pathname . slice ( atSignIndex + 1 ) )
208210 }
209211
210212 let rawNamespace
211213 let rawName
212214 const lastSlashIndex = beforeVersion . lastIndexOf ( '/' )
213215 if ( lastSlashIndex === - 1 ) {
214216 // Split the remainder once from right on '/'.
215- rawName = beforeVersion
217+ rawName = decodeURIComponent ( beforeVersion )
216218 } else {
217219 // Split the remainder once from right on '/'.
218- rawName = beforeVersion . slice ( lastSlashIndex + 1 )
220+ rawName = decodeURIComponent (
221+ beforeVersion . slice ( lastSlashIndex + 1 )
222+ )
219223 // Split the remainder on '/'.
220- rawNamespace = beforeVersion . slice ( 0 , lastSlashIndex )
224+ rawNamespace = decodeURIComponent (
225+ beforeVersion . slice ( 0 , lastSlashIndex )
226+ )
221227 }
222228
223229 let rawQualifiers
@@ -231,7 +237,7 @@ class PackageURL {
231237 const { hash } = url
232238 if ( hash . length !== 0 ) {
233239 // Split the purl string once from right on '#'.
234- rawSubpath = hash . slice ( 1 )
240+ rawSubpath = decodeURIComponent ( hash . slice ( 1 ) )
235241 }
236242
237243 return [
0 commit comments