jrit / web-resource-inliner

Inlines img, script and link tags into the same file
MIT License
66 stars 29 forks source link

Rebasing based on path module #49

Open GauntletPL opened 4 years ago

GauntletPL commented 4 years ago

Using path module to rebase remote resources causes URLs to be messed up and fail.

Example:

My HTML has Bootstrap css file referenced like this: <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

Bootstrap references font files like this: src:url(../fonts/glyphicons-halflings-regular.eot);

html.js is invoking css.js passing rebaseRelativeTo option calculated as path.join( settings.relativeTo, args.src, ".." + path.sep ). This produces https:/netdna.bootstrapcdn.com/bootstrap/3.3.7/css/ (double slash was lost as a result).

In the end https:/netdna.bootstrapcdn.com/bootstrap/3.3.7/css/ is not treated as a remote (RegExp test fails) and font is attempted to be retrieved from /local/directory/path/https:/netdna.bootstrapcdn.com/bootstrap/3.3.7/css\fonts/glyphicons-halflings-regular.eot

path.join() and path.relative() should not be used while dealing with remotes.