src: some refactoring of node_url.cc
-
src: minor cleanups to node_url.cc
- Remove pointless pointers
- Make
WriteHost
take a const argument so that it’s functionality is clear from the signature - Make
FindLongestZeroSequence
templated to accommodate the constness inWriteHost
and because usinguint16_t
is an articifial, unnecessary restriction - Remove string copying when no copies are needed
- Make
PercentDecode
just return its return value - Make
ParseHost
(string-only version) take its constant argument as a constant reference
-
src: move url internals into anonymous namespace
This helps because
static
doesn’t work for C++ classes, but refactoringurl_host
into a proper C++ class seems the most reasonable soluation for the memory leak fixed by the next commit. -
src: make url host a proper C++ class
- Gives
URLHost
a proper destructor that clears memory depending on the type of the host (This fixes a memory leak) - Hide the host type enums and class layout as implementation details
- Make the
Parse
methods members ofURLHost
- Turn
WriteHost
into aToString()
method on theURLHost
class - Verify that at the beginning of a parse attempt, the type is set to “failed”
- Remove a lot of
goto
s from the source code🐢 🚀
- Gives
-
src: use correct OOB check for IPv6 parsing
last_piece
pointed to the end of the 8×16 bit array, sopiece_pointer == last_piece
already means that the pointer is not writable any longer.Previously, this still worked most of the time but could result in an out-of-bounds-write.
Also, rename
last_piece
tobuffer_end
to avoid this pitfall.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
commit message follows commit guidelines
Affected core subsystem(s)
src/node_url.cc
Not sure how to write tests but it makes valgrind happy about @TimothyGu’s example from #17448 (closed)