6 Commits
Author SHA1 Message Date
Anna Henningsen 9181fbb699 src: dumb down code by removing std::move
This would require C++11 features that would
otherwise not be available on clang + OS X on Node 6.x.

PR-URL: https://github.com/nodejs/node/pull/18324
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
2018-02-12 19:28:37 -05:00
Anna Henningsen 57865a9213 src: use correct OOB check for IPv6 parsing
`last_piece` pointed to the end of the 8×16 bit array,
so `piece_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` to `buffer_end` to avoid this pitfall.

Backport-PR-URL: https://github.com/nodejs/node/pull/18324
PR-URL: https://github.com/nodejs/node/pull/17470
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2018-02-12 19:28:37 -05:00
Anna Henningsen f306d3eb7a 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 of `URLHost`
- Turn `WriteHost` into a `ToString()` method on the `URLHost` 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 🐢🚀

Backport-PR-URL: https://github.com/nodejs/node/pull/18324
PR-URL: https://github.com/nodejs/node/pull/17470
Fixes: https://github.com/nodejs/node/issues/17448
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2018-02-12 19:28:37 -05:00
Anna Henningsen 1976c7c7a5 src: move url internals into anonymous namespace
This helps because `static` doesn’t work for C++ classes,
but refactoring `url_host` into a proper C++ class seems the
most reasonable soluation for the memory leak fixed by the next commit.

Backport-PR-URL: https://github.com/nodejs/node/pull/18324
PR-URL: https://github.com/nodejs/node/pull/17470
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2018-02-12 19:28:36 -05:00
Anna Henningsen d66f469931 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
  in `WriteHost` and because using `uint16_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

Backport-PR-URL: https://github.com/nodejs/node/pull/18324
PR-URL: https://github.com/nodejs/node/pull/17470
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2018-02-12 19:28:36 -05:00
James M Snell 24def19417 url: adding WHATWG URL support
Implements WHATWG URL support. Example:

```
var u = new url.URL('http://example.org');
```

Many, many other commits improving the implementation have been squashed
into this backport PR. They are not listed separately here for brevity.

Backport-PR-URL: https://github.com/nodejs/node/pull/17365
PR-URL: https://github.com/nodejs/node/pull/7448
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
2018-02-12 19:28:11 -05:00