mozilla / mozilla/source-map

util.join() doesn't handle absolute path on Windows correctly

Open
#355 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feat
Dominant language
JavaScript
Stars
3.7k
Forks
370
PR merge metrics
No merged PRs in 30d

Description

We use the Webpack pipeline on Windows with sass-loader, postcss-loader, and css-loader. Then we found the generated source paths went crazy: F:\Projects\web-project-boilerplate\src\scss\index.scss just becomes F:/Projects/web-project-boilerplate/src/scss/F:/Projects/web-project-boilerplate/src/scss/F:/Projects/web-project-boilerplate/src/scss/index.scss.

As I followed the codebase in the pipeline, I noticed that the sass-loader use relative path, then the postcss-loader and css-loader turn to use absolute path for "sources" field in the sourceMap. In addition, the absolute path on Windows starts with a symbol of the disk driver, e.g. F: in our case. When it comes to sourceMap's util.join(), it only detects absolute path starts with /

https://github.com/mozilla/source-map/blob/c3a8f5a2a4cc7ac5bc6c06bc93745d3c57bd8860/lib/util.js#L228

So it joins multiple paths across the loaders.

Also, the util.isAbsolute doesn't deal with the Windows absolute path as well.

https://github.com/mozilla/source-map/blob/c3a8f5a2a4cc7ac5bc6c06bc93745d3c57bd8860/lib/util.js#L241

Appendix:
Here is a case of how expressjs test the absolute path:

exports.isAbsolute = function(path){
  if ('/' === path[0]) return true;
  if (':' === path[1] && ('\\' === path[2] || '/' === path[2])) return true; // Windows device path
  if ('\\\\' === path.substring(0, 2)) return true; // Microsoft Azure absolute path
};

I'm not sure we need to handle the azure absolute path, but I would be better if we had window device path included.

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/util.js at util.join() and util.isAbsolute(), using the reported Windows drive-letter path as the reproducer. Check how both entry points treat paths such as F:\Projects\... alongside slash-prefixed paths. Done means absolute Windows paths are recognized and are not repeatedly joined across the source-map loader pipeline; run the existing project tests afterward.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
devtools
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.