Skip to content
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

src: fix ThrowInvalidURL call in PathToFileURL #57141

Merged

Conversation

danielmbrasil
Copy link
Contributor

Fixes #57133.

Replaces nullptr with std::nullopt when calling ThrowInvalidURL in PathToFileURL. This ensures the function receives the correct argument type and aligns with the expected behavior.

PS: I'm not sure how to test this, any help would be appreciated.

Replace `nullptr` with `std::nullopt` when calling `ThrowInvalidURL` in
`PathToFileURL`. This ensures the function receives the correct argument
type and aligns with the expected behavior.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/url

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Feb 19, 2025
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 19, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 19, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.03%. Comparing base (f6ce486) to head (12b9054).
Report is 59 commits behind head on main.

Files with missing lines Patch % Lines
src/node_url.cc 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57141      +/-   ##
==========================================
+ Coverage   88.54%   89.03%   +0.49%     
==========================================
  Files         665      665              
  Lines      193408   193408              
  Branches    36961    37278     +317     
==========================================
+ Hits       171250   172205     +955     
+ Misses      14795    13884     -911     
+ Partials     7363     7319      -44     
Files with missing lines Coverage Δ
src/node_url.cc 79.53% <0.00%> (+0.29%) ⬆️

... and 93 files with indirect coverage changes

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@jazelly jazelly left a comment

Choose a reason for hiding this comment

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

should we also add a test?

@lemire
Copy link
Member

lemire commented Feb 21, 2025

Do we have a test with a malformed URL?

@juanarbol
Copy link
Member

should we also add a test?

I would say so.

Copy link
Member

@juanarbol juanarbol left a comment

Choose a reason for hiding this comment

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

LGTM once the test case is added. Thanks!

@geeksilva97
Copy link
Contributor

Do you guys have any clues about how to test this? I tried to reach such a condition, but I couldn't.

@anonrig
Copy link
Member

anonrig commented Feb 24, 2025

Do you guys have any clues about how to test this? I tried to reach such a condition, but I couldn't.

Adding a CC_TEST would be the fastest

@danielmbrasil
Copy link
Contributor Author

Adding a CC_TEST would be the fastest

@anonrig Do you have any examples of how to test this? As this is my first contribution I'm a bit lost on how to write a CC_TEST.

@lemire
Copy link
Member

lemire commented Feb 26, 2025

Let me elaborate on my comment above where I wrote "Do we have a test with a malformed URL?".

Here is the code:

  Utf8Value input(isolate, args[0]);
  auto input_str = input.ToStringView();
  CHECK(!input_str.empty());
  auto out =
       ada::parse<ada::url_aggregator>(EncodePathChars(input_str, os), nullptr);

   if (!out) {
     return ThrowInvalidURL(realm->env(), input.ToStringView(), somethinghere);
   }

The question is whether we have a test that triggers the if(!out) check.

@lemire
Copy link
Member

lemire commented Feb 26, 2025

@juanarbol @anonrig @jazelly @geeksilva97

Would you object to this fix getting merged without a test. I think we have no test that would trigger this issue, but by reading the code, what I expect happens when the problematic code path is triggered... is that you get a hard crash.

This is a confirmed bug, I think that there is no disagreement about that. The fix looks correct to all of us. I think we should not block the fix due to a lack of good test.

@geeksilva97
Copy link
Contributor

@juanarbol @anonrig @jazelly @geeksilva97

Would you object to this fix getting merged without a test. I think we have no test that would trigger this issue, but by reading the code, what I expect happens when the problematic code path is triggered... is that you get a hard crash.

This is a confirmed bug, I think that there is no disagreement about that. The fix looks correct to all of us. I think we should not block the fix due to a lack of good test.

No objection from my side.

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 26, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 26, 2025
@nodejs-github-bot nodejs-github-bot merged commit fd45383 into nodejs:main Feb 26, 2025
70 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in fd45383

@danielmbrasil danielmbrasil deleted the fix/invalid-string-construction branch February 26, 2025 14:36
aduh95 pushed a commit that referenced this pull request Mar 9, 2025
Replace `nullptr` with `std::nullopt` when calling `ThrowInvalidURL` in
`PathToFileURL`. This ensures the function receives the correct argument
type and aligns with the expected behavior.

PR-URL: #57141
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid string construction
7 participants