Skip to content

Commit

Permalink
fix: check file exists (#35)
Browse files Browse the repository at this point in the history
* chore: remove travis and appver

Co-authored-by: wanghx <whx89768@antgroup.com>
  • Loading branch information
whxaxes and wanghx committed Aug 18, 2022
1 parent 55d27e6 commit 00d2aa2
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 31 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/nodejs.yml
@@ -0,0 +1,46 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
schedule:
- cron: '0 2 * * *'

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
node-version: [14, 16]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout Git Source
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm i -g npminstall@5 && npminstall

- name: Continuous Integration
run: npm run ci

- name: Code Coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

15 changes: 0 additions & 15 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion lib/error_view.js
Expand Up @@ -128,7 +128,7 @@ class ErrorView {
const lineNumber = frame.getLineNumber();
let contents = this.getAssets(filename);
if (!contents) {
contents = fs.readFileSync(filename, 'utf8');
contents = fs.existsSync(filename) ? fs.readFileSync(filename, 'utf8') : '';
this.setAssets(filename, contents);
}
const lines = contents.split(/\r?\n/);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -52,7 +52,7 @@
"autod": "autod"
},
"ci": {
"version": "8, 9"
"version": "14, 16"
},
"author": "dead_horse"
}
6 changes: 6 additions & 0 deletions test/fixtures/onerror/app/controller/home.js
Expand Up @@ -14,6 +14,12 @@ exports.index = function* () {
throw err;
};

exports.unknownFile = function* () {
const err = new Error('test error');
err.stack = err.stack.replace(/(controller\/home\.)js/, '$1ts');
throw err;
};

exports.csrf = function* () {
this.set('x-csrf', this.csrf);
this.body = 'test';
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/onerror/app/router.js
Expand Up @@ -2,6 +2,7 @@

module.exports = app => {
app.get('/', app.controller.home.index);
app.get('/unknownFile', app.controller.home.unknownFile);
app.get('/csrf', app.controller.home.csrf);
app.post('/test', app.controller.home.test);
app.get('/user', app.controller.user);
Expand Down
9 changes: 8 additions & 1 deletion test/onerror.test.js
Expand Up @@ -46,6 +46,13 @@ describe('test/onerror.test.js', () => {
.expect(500);
});

it('should handle not exists file in stack without error', () => {
return app.httpRequest()
.get('/unknownFile')
.expect(/<div class="context">test error<\/div>/)
.expect(500);
});

it('should handle escape xss', () => {
return app.httpRequest()
.get('/?message=<script></script>')
Expand Down Expand Up @@ -277,7 +284,7 @@ describe('test/onerror.test.js', () => {
yield app.httpRequest()
.post('/body_parser')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send({ foo: new Buffer(1024 * 100).fill(1).toString() })
.send({ foo: new Buffer(1024 * 1000).fill(1).toString() })
.expect(/request entity too large/)
.expect(413);
yield app.close();
Expand Down

0 comments on commit 00d2aa2

Please sign in to comment.