Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
src: fix string_view constructor call for IsIPv4NumberValid in node_u…
…rl.cc
  • Loading branch information
miguelteixeiraa committed Jan 17, 2023
commit 573dd4af7dda4da573f6f165f5f5898852a46f1d
4 changes: 2 additions & 2 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ bool EndsInANumber(const std::string_view input) {
return true;
}

return IsIPv4NumberValid(std::string_view(
pointer_start, std::distance(pointer_start, pointer_end)));
return IsIPv4NumberValid(
std::string_view(&*pointer_start, pointer_end - pointer_start));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is too hacky (even if it's guaranteed safe).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed!

Copy link
Copy Markdown
Contributor Author

@miguelteixeiraa miguelteixeiraa Jan 18, 2023

Choose a reason for hiding this comment

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

I'll try a static_cast<const char*>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@nodejs/cpp-reviewers any recommendations?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah: I would definitely recommeng to go back to the original "hacky" implementation. It works and looks correct, even if it is not visually pretty. (I'd also not call this pointer if it's an iterator.) const_cast<char*>(pointer_start) doesn't even really make sense since the string_view constructor takes a const char* argument.

Copy link
Copy Markdown
Contributor Author

@miguelteixeiraa miguelteixeiraa Jan 18, 2023

Choose a reason for hiding this comment

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

Yes, I think it only works on the other compilers because their implementations for the iterator are:
std::string_view::iterator' (aka 'const char *')
(I purposely caused an error to catch this 'aka' haha)

}

void URLHost::ParseIPv4Host(const char* input, size_t length) {
Expand Down