(context: string, maybeAbsolutePath: string)
| 33 | }; |
| 34 | |
| 35 | const absoluteToRequest = (context: string, maybeAbsolutePath: string): string => { |
| 36 | if (maybeAbsolutePath[0] === '/') { |
| 37 | if (maybeAbsolutePath.length > 1 && maybeAbsolutePath[maybeAbsolutePath.length - 1] === '/') { |
| 38 | // this 'path' is actually a regexp generated by dynamic requires. |
| 39 | // Don't treat it as an absolute path. |
| 40 | return maybeAbsolutePath; |
| 41 | } |
| 42 | |
| 43 | const querySplitPos = maybeAbsolutePath.indexOf('?'); |
| 44 | let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos); |
| 45 | resource = relativePathToRequest(path.posix.relative(context, resource)); |
| 46 | return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos); |
| 47 | } |
| 48 | |
| 49 | if (WINDOWS_ABS_PATH_REGEXP.test(maybeAbsolutePath)) { |
| 50 | const querySplitPos = maybeAbsolutePath.indexOf('?'); |
| 51 | let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos); |
| 52 | resource = path.win32.relative(context, resource); |
| 53 | if (!WINDOWS_ABS_PATH_REGEXP.test(resource)) { |
| 54 | resource = relativePathToRequest(resource.replace(WINDOWS_PATH_SEPARATOR_REGEXP, '/')); |
| 55 | } |
| 56 | return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos); |
| 57 | } |
| 58 | |
| 59 | // not an absolute path |
| 60 | return maybeAbsolutePath; |
| 61 | }; |
| 62 | |
| 63 | const _contextify = (context: string, request: string): string => { |
| 64 | return request |
no test coverage detected