eggjs / egg-cors
Showing 1 of 4 files from the diff.
Other files ignored by Codecov
appveyor.yml has changed.
package.json has changed.
test/cors.test.js has changed.

@@ -1,6 +1,7 @@
Loading
1 1
'use strict';
2 2
3 -
const url = require('url');
3 +
// there is no global.URL in node 8
4 +
const URL = require('url').URL;
4 5
5 6
module.exports = app => {
6 7
  // put before other core middlewares
@@ -12,8 +13,16 @@
Loading
12 13
    const origin = ctx.get('origin');
13 14
    if (!origin) return '';
14 15
15 -
    const parsedUrl = url.parse(origin);
16 -
    if (!ctx.isSafeDomain || ctx.isSafeDomain(parsedUrl.hostname) || ctx.isSafeDomain(origin)) {
16 +
    if (typeof ctx.isSafeDomain !== 'function') return origin;
17 +
18 +
    let parsedUrl;
19 +
    try {
20 +
      parsedUrl = new URL(origin);
21 +
    } catch (err) {
22 +
      return '';
23 +
    }
24 +
25 +
    if (ctx.isSafeDomain(parsedUrl.hostname) || ctx.isSafeDomain(origin)) {
17 26
      return origin;
18 27
    }
19 28
    return '';
Files Coverage
app.js 100.00%
app/middleware/cors.js 100.00%
config/config.default.js 100.00%
Project Totals (3 files) 100.00%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading