Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/extractLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function evalDependencyGraph({loaderContext, src, filename, publicPath = ""}) {
exports,
__webpack_public_path__: publicPath, // eslint-disable-line camelcase
require: givenRelativePath => {
const indexOfQuery = Math.max(givenRelativePath.indexOf("?"), givenRelativePath.length);
const noDoubleQuestionMarkPath = givenRelativePath.replace(/\?\?/g, "##");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is ?? part of a valid url? Also if you handled ??, why didn't you also handle ????

I don't think you need to handle these anyways. You should just focus on fixing the query part which was handled wrongly in the original code and leave these other cases to the judgement of the person using it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a test case failing, it was related to double question mark. I believe it is valid in webpack context.

const indexOfQuery = noDoubleQuestionMarkPath.includes("?") ? noDoubleQuestionMarkPath.indexOf("?") : givenRelativePath.length;
Copy link

@smac89 smac89 Apr 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A shorter way of accomplishing the same thing is:

const indexOfQuery = givenRelativePath.search(/(\?.*)?$/);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it but code is meant to be readable and understandable. I'm going to leave the decision to the maintainer.

const relativePathWithoutQuery = givenRelativePath.slice(0, indexOfQuery);
const indexOfLastExclMark = relativePathWithoutQuery.lastIndexOf("!");
const query = givenRelativePath.slice(indexOfQuery);
Expand Down