Skip to content

Commit

Permalink
Feat: Strip querystring-like trailers from local paths (#7)
Browse files Browse the repository at this point in the history
When discovering that a normalized file path contains a '?' character, everything (including the '?' character itself) will be stripped from it.

Fixes #7.
  • Loading branch information
macedigital committed Jul 6, 2017
1 parent 25af3d8 commit 04ff6e9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ function normalizePath(node, config) {
src = path.sep + src;
}

// remove query-string from path
if (src.indexOf('?') !== -1) {
return src.substr(0, src.indexOf('?'));
}

return src;
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/flat/transform.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/styles.css?v=123">
<link rel="stylesheet" href="css/styles.css" media="screen">
<link rel="stylesheet alternate" href="http://insecure.com/style.css?version=1">
<link rel="stylesheet" href="https://secure.com/css/styles.css">
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/nested/folder/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</head>
<body>
<h1>Title</h1>
<script src="../scripts/script.js" data-sri-hash="1"></script>
<script src="../scripts/script.js?v=123" data-sri-hash="1"></script>
</body>
</html>

0 comments on commit 04ff6e9

Please sign in to comment.