Repository: pinojs/hapi-pino (js)

Issue:
Not handling correctly `request.url` being undefined
Starting with Hapi@18, all extensions on the`onRequest` event need to handle that [`request.url` might be undefined](https://github.com/hapijs/hapi/issues/3871).

> if you have onRequest extension handlers, make sure your code can handle request.url being set to null if the request.path received is invalid.

We recently had a problem with hapi-pino, because the `isLoggingIgnored` functions threw a type error.

```javascript
  function isLoggingIgnored (options, request) {
   // request.url can be undefined at this point;
    if (options.ignorePaths && ignoreTable[request.url.pathname]) {
      return true
    }
```

Pull request description:
[master] fix: get securely pathname from request url
Fixes #102 

Patch:
diff --git a/index.js b/index.js
index 5937b6e..41bf6d5 100644
--- a/index.js
+++ b/index.js
@@ -172,7 +172,8 @@ async function register (server, options) {
   })
 
   function isLoggingIgnored (options, request) {
-    if (options.ignorePaths && ignoreTable[request.url.pathname]) {
+    // note: from hapi@18.0.0 the `request.url` can be undefined
+    if (options.ignorePaths && request.url && ignoreTable[request.url.pathname]) {
       return true
     }
 


Test patch:
diff --git a/test.js b/test.js
index 4ae7ea2..8c02026 100644
--- a/test.js
+++ b/test.js
@@ -1458,6 +1458,38 @@ experiment('logging with request payload', () => {
   })
 })
 
+experiment('logging with invalid request', () => {
+  test('registered with ignored path and invalid injected', async () => {
+    const server = getServer()
+    let resolver
+    const done = new Promise((resolve, reject) => {
+      resolver = resolve
+    })
+    const stream = sink(data => {
+      expect(data.req.url).to.be.undefined()
+      resolver()
+    })
+    const logger = require('pino')(stream)
+    const plugin = {
+      plugin: Pino,
+      options: {
+        instance: logger,
+        ignorePaths: ['/ignored']
+      }
+    }
+
+    await server.register(plugin)
+
+    await server.inject({
+      method: 'PUT',
+      url: '/ignored'
+    })
+
+    await server.inject('invalid')
+    await done
+  })
+})
+
 experiment('ignore request logs for paths in ignorePaths', () => {
   test('when path matches entry in ignorePaths, nothing should be logged', async () => {
     const server = getServer()