@@ -9,6 +9,7 @@ const chalk = require('chalk');
9
9
const mkpath = require ( 'mkpath' ) ;
10
10
const jsonfile = require ( 'jsonfile' ) ;
11
11
const cheerio = require ( 'cheerio' ) ;
12
+ const normalurl = require ( 'normalize-url' ) ;
12
13
const limitSimilar = require ( './limit-similar' ) ;
13
14
14
15
const dirname = path . dirname ;
@@ -99,11 +100,22 @@ function crawl(url, flags) {
99
100
// Clone the default scenario and adjust urls as needed
100
101
const currentScenario = Object . assign ( { } , defaultScenario ) ;
101
102
currentScenario . label = queueItem . path ;
103
+ currentScenario . url = queueItem . url ;
104
+
102
105
if ( flags . referenceUrl ) {
103
- currentScenario . referenceUrl = queueItem . url . replace (
104
- url ,
105
- flags . referenceUrl
106
+ // Normalize the URL to remove duplicate slashes. See #25
107
+ currentScenario . referenceUrl = normalurl (
108
+ queueItem . url . replace (
109
+ url ,
110
+ flags . referenceUrl
111
+ )
106
112
) ;
113
+
114
+ // Add a trailing slash to referenceUrl if url has a trailing slash and referenceUrl does not
115
+ if ( currentScenario . url . substr ( - 1 ) === '/' && currentScenario . referenceUrl . substr ( - 1 ) !== '/' ) {
116
+ currentScenario . referenceUrl += '/' ;
117
+ }
118
+
107
119
} else if (
108
120
Object . prototype . hasOwnProperty . call (
109
121
currentScenario ,
@@ -112,7 +124,7 @@ function crawl(url, flags) {
112
124
) {
113
125
delete currentScenario . referenceUrl ;
114
126
}
115
- currentScenario . url = queueItem . url ;
127
+
116
128
urls . push ( currentScenario ) ;
117
129
}
118
130
} ) ;
0 commit comments