@@ -421,10 +421,25 @@ methods.isPartOfBaseUrl = (defaultUrl, defaultSecureUrl, urlPart) => {
421
421
return defaultUrl . indexOf ( urlPart ) >= 0 || defaultSecureUrl . indexOf ( urlPart ) >= 0
422
422
}
423
423
424
- // NOTE: we assume that the urlPart is after the protocol
425
- methods . findIntersection = ( defaultUrl , urlPart ) => {
426
- const match = ( defaultUrl + '####' + urlPart ) . match ( / ^ .* ?( .* ) # # # # \1( .* ) $ / )
424
+ /**
425
+ * finds the intersection between two strings, and returns the intersection, as well as the right-
426
+ * most exclusion. This is used to find the overlap between a host url and a part of a url
427
+ * associated with that host.
428
+ * @param {string } defaultUrl: the default url to test against.
429
+ * @param {string } defaultSecureUrl: the default secure url to test against.
430
+ * @param {string } urlPart: the part of url to test
431
+ * @returns {{ inside: string, outside: string } }
432
+ *
433
+ * Note: this assumes Paw only supports http and https.
434
+ * Note: this may work incorrectly if url is as follow: http://example.com/example.com/ (not tested)
435
+ */
436
+ methods . findIntersection = ( defaultUrl , defaultSecureUrl , urlPart ) => {
437
+ let baseUrl = defaultUrl
438
+ if ( urlPart . match ( / ^ [ ^ : ] * s : \/ \/ / ) ) {
439
+ baseUrl = defaultSecureUrl
440
+ }
427
441
442
+ const match = ( baseUrl + '####' + urlPart ) . match ( / ^ .* ?( .* ) # # # # \1( .* ) $ / )
428
443
// always matches
429
444
return { inside : match [ 1 ] , outside : match [ 2 ] }
430
445
}
@@ -452,15 +467,18 @@ methods.addComponentToBaseOrPath = (
452
467
{ baseComponents, pathComponents } ,
453
468
{ key : urlPart , value : component }
454
469
) => {
455
- if ( methods . isPartOfBaseUrl ( defaultUrl , defaultSecureUrl , urlPart ) ) {
470
+ if (
471
+ pathComponents . length === 0 &&
472
+ methods . isPartOfBaseUrl ( defaultUrl , defaultSecureUrl , urlPart )
473
+ ) {
456
474
// component is member of base url
457
475
baseComponents . push ( { key : urlPart , value : component } )
458
476
return { baseComponents, pathComponents }
459
477
}
460
478
461
479
if ( pathComponents . length === 0 ) {
462
480
// component may be split between base url and path
463
- const { inside, outside } = methods . findIntersection ( defaultUrl , urlPart )
481
+ const { inside, outside } = methods . findIntersection ( defaultUrl , defaultSecureUrl , urlPart )
464
482
baseComponents . push ( { key : inside , value : inside } )
465
483
pathComponents . push ( { key : outside , value : outside } )
466
484
}
0 commit comments