-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cdnizer 2.0.0 appears to apply quotes randomly #29
Comments
Hey there! Sorry you are having a problem here. This issue is related to the leading Luckily, the solution / workaround is easy: don't start with
Though I recommend you use a more specific matcher like Thanks for the report! I'll leave this open for others to find until I have a chance to fix the issue, but it could be a long time. |
- This doesn't actually fix the issue, but provides some basic code that can be used to verify the issue is fixed in the future.
Note to self: I think this is directly related to issue #20, which also featured a leading |
Thanks for you quick response and suggestions. At first I didn't want to use the more specific prefixes you're suggesting, because the input html is generated from a template in which the node_modules prefix is taken from a configuration file. The prefix could be anything, for example Still, I reached a compromise that kind of works. I changed the glob pattern to At this point, I discovered something. If I comment out the second pattern in As it stands, I'm better off using I can think of a workaround for this scenario: after passing the url to minimatch, strip quotes from the |
I'm not sure I'd be OK always outputting a modification without quotes. The regexes a supposed to preserve the existing quotes as a best as they can. There's clearly some quirks with this library, it's definitely not a "smart" library (as it doesn't parse the HTML at all). Honestly, I'd hate to see you put in the time, it could be weeks before I have any free time to dig into this further. So I don't want to promise I'll accept or even get time to review any PRs in the near future. |
If it puts your mind at ease: the workaround that I'm proposing doesn't always cause cdnizer to strip quotes in the replacement. Rather, it only does so in the pathological case that this issue ticket is about. I think that roughly the following is currently happening.
Now, html attribute values logically shouldn't ever contain quotes, since quotes are reserved for delimiting them. If you find a trailing quote in step 5, then the previous steps must have gone wrong as I described. So you can safely strip that trailing quote. Another option would be to prevent step 3 from happening. You can stop the pattern from matching quoted urls by adjusting the middle group. Right now, that group is Either way, my pull request would likely affect only one or two lines of code. Reviewing that would take less of your time than this discussion has already taken. I'll wait for your green light before doing anything, though. |
I like your solution to fixing the regex, which is definitely a bit too aggressive. Thanks for taking the time to look into this, I'd definitely accept the PR. The only thing left is I'm internally debating if this is a breaking change or not. Sadly, I think it is, even though it's really a bug fix, but someone could, theoretically, be relying on that aggressive regex. I understand that the fix is simple, but I have to decide whether this would be a breaking change or not, and ensure that there's tests in place, etc. Then I have to deploy it. (It's usually rather quick, but I have a full time job, a family, etc. So time is always at a premium.) Honestly, I'd rather it take longer to discuss a fix than review it! It means that the problem was better understood, and the solution wasn't rushed. Especially with a library like this, where I only touch it once in a while, so it always takes me some time to remember how everything works. |
I'll patiently wait for your internal debate to come to a conclusion. In the meanwhile: do I understand correctly that you prefer the regex adjustment over the quote stripping? |
Oh, sorry, I meant that I'll totally accept a PR for fixing the regex. The only decision then is whether to deploy it as a breaking (major) change or bugfix (minor change), but I'll probably just roll it out as a breaking change on both repos (cdnizer/gulp-cdnizer) to avoid any headaches. |
I think some of the other regexes could be a bit stricter, too. Should I submit fixes for all regexes, given that you'll bring out a major release anyway? |
Sure, that would be great, thanks! |
Hi there, |
I think I forgot about this. I'll put it back on my to-do list, but I can't currently give any prediction on when I'll be able to submit the PR as agreed. |
At first sight, the failing test seems to suggest that every odd <script> has a quote stripped while every even <script> does not. This order change reveals that it is not the order, but the content of the src= attribute that influences the behavior. The URLs from cdnjs have a quote stripped, the URLs from jsdelivr do not.
I just debugged the issue in detail and found that the cause is a bit different from what I thought. In the |
Closed by #40 |
Input:
cdnizer call:
Output (note the incoherent presence and absence of quotes):
Output after a second run:
My browser (Safari 11) attempts to load https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js%22, which fails with a 403 status, so the uneven quoting really breaks things.
The text was updated successfully, but these errors were encountered: