Skip to content

Commit fbf723b

Browse files
committed
Merge branch 'chore/collapseLeadingSlashes' of https://github.com/Ayoub-Mabrouk/serve-static into chore/collapseLeadingSlashes
2 parents 9a94734 + af7cd7b commit fbf723b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

index.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,14 @@ function serveStatic (root, options) {
127127

128128
/**
129129
* Collapse all leading slashes into a single slash
130+
*
131+
* @param {string} str
132+
* @returns {string}
130133
* @private
131134
*/
132-
function collapseLeadingSlashes (str) {
133-
for (var i = 0; i < str.length; i++) {
134-
if (str.charCodeAt(i) !== 0x2f /* / */) {
135-
break
136-
}
137-
}
138135

139-
return i > 1
140-
? '/' + str.substr(i)
141-
: str
136+
function collapseLeadingSlashes (str) {
137+
return str.replace(/^\/+/, '/') || '/'
142138
}
143139

144140
/**

0 commit comments

Comments
 (0)