@@ -12,34 +12,22 @@ function ownKeys(object, enumerableOnly) {
12
12
13
13
if ( Object . getOwnPropertySymbols ) {
14
14
var symbols = Object . getOwnPropertySymbols ( object ) ;
15
-
16
- if ( enumerableOnly ) {
17
- symbols = symbols . filter ( function ( sym ) {
18
- return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ;
19
- } ) ;
20
- }
21
-
22
- keys . push . apply ( keys , symbols ) ;
15
+ enumerableOnly && ( symbols = symbols . filter ( function ( sym ) {
16
+ return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ;
17
+ } ) ) , keys . push . apply ( keys , symbols ) ;
23
18
}
24
19
25
20
return keys ;
26
21
}
27
22
28
23
function _objectSpread2 ( target ) {
29
24
for ( var i = 1 ; i < arguments . length ; i ++ ) {
30
- var source = arguments [ i ] != null ? arguments [ i ] : { } ;
31
-
32
- if ( i % 2 ) {
33
- ownKeys ( Object ( source ) , true ) . forEach ( function ( key ) {
34
- _defineProperty ( target , key , source [ key ] ) ;
35
- } ) ;
36
- } else if ( Object . getOwnPropertyDescriptors ) {
37
- Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) ;
38
- } else {
39
- ownKeys ( Object ( source ) ) . forEach ( function ( key ) {
40
- Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ;
41
- } ) ;
42
- }
25
+ var source = null != arguments [ i ] ? arguments [ i ] : { } ;
26
+ i % 2 ? ownKeys ( Object ( source ) , ! 0 ) . forEach ( function ( key ) {
27
+ _defineProperty ( target , key , source [ key ] ) ;
28
+ } ) : Object . getOwnPropertyDescriptors ? Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) : ownKeys ( Object ( source ) ) . forEach ( function ( key ) {
29
+ Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ;
30
+ } ) ;
43
31
}
44
32
45
33
return target ;
@@ -48,17 +36,11 @@ function _objectSpread2(target) {
48
36
function _typeof ( obj ) {
49
37
"@babel/helpers - typeof" ;
50
38
51
- if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) {
52
- _typeof = function ( obj ) {
53
- return typeof obj ;
54
- } ;
55
- } else {
56
- _typeof = function ( obj ) {
57
- return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ;
58
- } ;
59
- }
60
-
61
- return _typeof ( obj ) ;
39
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol . iterator ? function ( obj ) {
40
+ return typeof obj ;
41
+ } : function ( obj ) {
42
+ return obj && "function" == typeof Symbol && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ;
43
+ } , _typeof ( obj ) ;
62
44
}
63
45
64
46
function _classCallCheck ( instance , Constructor ) {
@@ -80,6 +62,9 @@ function _defineProperties(target, props) {
80
62
function _createClass ( Constructor , protoProps , staticProps ) {
81
63
if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ;
82
64
if ( staticProps ) _defineProperties ( Constructor , staticProps ) ;
65
+ Object . defineProperty ( Constructor , "prototype" , {
66
+ writable : false
67
+ } ) ;
83
68
return Constructor ;
84
69
}
85
70
@@ -294,18 +279,21 @@ var ImgixClient = /*#__PURE__*/function () {
294
279
_createClass ( ImgixClient , [ {
295
280
key : "buildURL" ,
296
281
value : function buildURL ( ) {
297
- var path = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : '' ;
282
+ var rawPath = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : '' ;
298
283
var params = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
284
+ var options = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ;
299
285
300
- var sanitizedPath = this . _sanitizePath ( path ) ;
286
+ var path = this . _sanitizePath ( rawPath , {
287
+ encode : ! options . disablePathEncoding
288
+ } ) ;
301
289
302
290
var finalParams = this . _buildParams ( params ) ;
303
291
304
292
if ( ! ! this . settings . secureURLToken ) {
305
- finalParams = this . _signParams ( sanitizedPath , finalParams ) ;
293
+ finalParams = this . _signParams ( path , finalParams ) ;
306
294
}
307
295
308
- return this . settings . urlPrefix + this . settings . domain + sanitizedPath + finalParams ;
296
+ return this . settings . urlPrefix + this . settings . domain + path + finalParams ;
309
297
}
310
298
} , {
311
299
key : "_buildParams" ,
@@ -331,23 +319,38 @@ var ImgixClient = /*#__PURE__*/function () {
331
319
key : "_signParams" ,
332
320
value : function _signParams ( path , queryParams ) {
333
321
var signatureBase = this . settings . secureURLToken + path + queryParams ;
334
- var signature = md5__default [ ' default' ] ( signatureBase ) ;
322
+ var signature = md5__default [ " default" ] ( signatureBase ) ;
335
323
return queryParams . length > 0 ? queryParams + '&s=' + signature : '?s=' + signature ;
336
324
}
325
+ /**
326
+ * "Sanitize" the path of the image URL.
327
+ * Ensures that the path has a leading slash, and that the path is correctly
328
+ * encoded. If it's a proxy path (begins with http/https), then encode the
329
+ * whole path as a URI component, otherwise only encode specific characters.
330
+ * @param {string } path The URL path of the image
331
+ * @param {Object } options Sanitization options
332
+ * @param {boolean } options.encode Whether to encode the path, default true
333
+ * @returns {string } The sanitized path
334
+ */
335
+
337
336
} , {
338
337
key : "_sanitizePath" ,
339
338
value : function _sanitizePath ( path ) {
339
+ var options = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
340
+
340
341
// Strip leading slash first (we'll re-add after encoding)
341
342
var _path = path . replace ( / ^ \/ / , '' ) ;
342
343
343
- if ( / ^ h t t p s ? : \/ \/ / . test ( _path ) ) {
344
- // Use de/encodeURIComponent to ensure *all* characters are handled,
345
- // since it's being used as a path
346
- _path = encodeURIComponent ( _path ) ;
347
- } else {
348
- // Use de/encodeURI if we think the path is just a path,
349
- // so it leaves legal characters like '/' and '@' alone
350
- _path = encodeURI ( _path ) . replace ( / [ # ? : + ] / g, encodeURIComponent ) ;
344
+ if ( ! ( options . encode === false ) ) {
345
+ if ( / ^ h t t p s ? : \/ \/ / . test ( _path ) ) {
346
+ // Use de/encodeURIComponent to ensure *all* characters are handled,
347
+ // since it's being used as a path
348
+ _path = encodeURIComponent ( _path ) ;
349
+ } else {
350
+ // Use de/encodeURI if we think the path is just a path,
351
+ // so it leaves legal characters like '/' and '@' alone
352
+ _path = encodeURI ( _path ) . replace ( / [ # ? : + ] / g, encodeURIComponent ) ;
353
+ }
351
354
}
352
355
353
356
return '/' + _path ;
@@ -369,9 +372,12 @@ var ImgixClient = /*#__PURE__*/function () {
369
372
370
373
} , {
371
374
key : "_buildSrcSetPairs" ,
372
- value : function _buildSrcSetPairs ( path , params , options ) {
375
+ value : function _buildSrcSetPairs ( path ) {
373
376
var _this = this ;
374
377
378
+ var params = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
379
+ var options = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ;
380
+
375
381
var _validateAndDestructu = validateAndDestructureOptions ( options ) ,
376
382
_validateAndDestructu2 = _slicedToArray ( _validateAndDestructu , 3 ) ,
377
383
widthTolerance = _validateAndDestructu2 [ 0 ] ,
@@ -390,15 +396,20 @@ var ImgixClient = /*#__PURE__*/function () {
390
396
var srcset = targetWidthValues . map ( function ( w ) {
391
397
return "" . concat ( _this . buildURL ( path , _objectSpread2 ( _objectSpread2 ( { } , params ) , { } , {
392
398
w : w
393
- } ) ) , " " ) . concat ( w , "w" ) ;
399
+ } ) , {
400
+ disablePathEncoding : options . disablePathEncoding
401
+ } ) , " " ) . concat ( w , "w" ) ;
394
402
} ) ;
395
403
return srcset . join ( ',\n' ) ;
396
404
}
397
405
} , {
398
406
key : "_buildDPRSrcSet" ,
399
- value : function _buildDPRSrcSet ( path , params , options ) {
407
+ value : function _buildDPRSrcSet ( path ) {
400
408
var _this2 = this ;
401
409
410
+ var params = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
411
+ var options = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ;
412
+
402
413
if ( options . devicePixelRatios ) {
403
414
validateDevicePixelRatios ( options . devicePixelRatios ) ;
404
415
}
@@ -420,13 +431,17 @@ var ImgixClient = /*#__PURE__*/function () {
420
431
return "" . concat ( _this2 . buildURL ( path , _objectSpread2 ( _objectSpread2 ( { } , params ) , { } , {
421
432
dpr : dpr ,
422
433
q : params . q || qualities [ dpr ] || qualities [ Math . floor ( dpr ) ]
423
- } ) ) , " " ) . concat ( dpr , "x" ) ;
434
+ } ) , {
435
+ disablePathEncoding : options . disablePathEncoding
436
+ } ) , " " ) . concat ( dpr , "x" ) ;
424
437
} ;
425
438
426
439
var srcset = disableVariableQuality ? targetRatios . map ( function ( dpr ) {
427
440
return "" . concat ( _this2 . buildURL ( path , _objectSpread2 ( _objectSpread2 ( { } , params ) , { } , {
428
441
dpr : dpr
429
- } ) ) , " " ) . concat ( dpr , "x" ) ;
442
+ } ) , {
443
+ disablePathEncoding : options . disablePathEncoding
444
+ } ) , " " ) . concat ( dpr , "x" ) ;
430
445
} ) : targetRatios . map ( function ( dpr ) {
431
446
return withQuality ( path , params , dpr ) ;
432
447
} ) ;
0 commit comments