Skip to content

Commit

Permalink
Merge pull request #9 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Dec 6, 2023
2 parents d127039 + 360fc48 commit fe5f104
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 32 deletions.
16 changes: 2 additions & 14 deletions .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,13 @@ jobs:
runs-on: ubuntu-latest
container:
image: returntocorp/semgrep
if: (github.actor != 'dependabot[bot]')
steps:
- uses: actions/checkout@v4
- run: semgrep ci
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}

semgrep-github:
name: Scan
runs-on: ubuntu-latest
container:
image: returntocorp/semgrep
if: (github.actor != 'dependabot[bot]')
if: (github.triggering_actor != 'dependabot[bot]')
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v4
- run: semgrep ci --sarif --output=semgrep.sarif
- run: semgrep ci --sarif > semgrep.sarif
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
- name: Upload SARIF file for GitHub Advanced Security Dashboard
Expand Down
10 changes: 7 additions & 3 deletions lib/middleware/onerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ module.exports = async (ctx, next) => {
});
}
} catch (err) {
// Append v2 route path
ctx.request.path = (ctx.mountPath ?? '') + ctx.request.path;
ctx._matchedRoute = ctx._matchedRoute ? (ctx.mountPath ?? '') + ctx._matchedRoute : ctx.request.path;
if (err instanceof Error && !err.stack.split('\n')[1].includes('lib/middleware/parameter.js')) {
// Append v2 route path if a route throws an error
// since koa-mount will remove the mount path from ctx.request.path
// https://github.com/koajs/mount/issues/62
ctx.request.path = (ctx.mountPath ?? '') + ctx.request.path;
ctx._matchedRoute = ctx._matchedRoute ? (ctx.mountPath ?? '') + ctx._matchedRoute : ctx._matchedRoute;
}

let message = err;
if (err.name && (err.name === 'HTTPError' || err.name === 'RequestError')) {
Expand Down
3 changes: 1 addition & 2 deletions lib/v2/fisher-spb/news.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
Expand All @@ -16,7 +15,7 @@ module.exports = async (ctx) => {
responseType: 'buffer',
});

const $ = cheerio.load(iconv.decode(response.data, 'windows-1251'));
const $ = cheerio.load(response.data);

const descBuilder = (element) => {
const content = cheerio.load(`<p>${$('.news-message-text', element).html()}</p>`).root();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
},
"devDependencies": {
"@microsoft/eslint-formatter-sarif": "3.0.0",
"@stylistic/eslint-plugin-js": "1.4.1",
"@stylistic/eslint-plugin-js": "1.5.0",
"@types/aes-js": "3.1.4",
"@types/crypto-js": "4.2.1",
"@types/eslint": "8.44.8",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/middleware/onerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ describe('v2 route throws an error', () => {
expect(value).toBe('7');
break;
case 'Hot Routes:':
expect(value).toBe('4 /test/:id<br>1 /test/slow<br>1 /thisDoesNotExist<br>');
expect(value).toBe('4 /test/:id<br>');
break;
case 'Hot Paths:':
expect(value).toBe('2 /test/error<br>2 /test/slow<br>1 /test/httperror<br>1 /thisDoesNotExist<br>1 /<br>');
break;
case 'Hot Error Routes:':
expect(value).toBe('3 /test/:id<br>1 /test/slow<br>1 /thisDoesNotExist<br>');
expect(value).toBe('3 /test/:id<br>');
break;
case 'Hot Error Paths:':
expect(value).toBe('2 /test/error<br>1 /test/httperror<br>1 /test/slow<br>1 /thisDoesNotExist<br>');
Expand Down
2 changes: 1 addition & 1 deletion test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function checkRSS(response) {
expect(date).toEqual(expect.any(String));
expect(Date.parse(date)).toEqual(expect.any(Number));
expect(new Date() - new Date(date)).toBeGreaterThan(-1000 * 60 * 60 * 24 * 5);
expect(new Date() - new Date(date)).toBeLessThan(1000 * 60 * 60 * 24 * 30 * 12 * 5);
expect(new Date() - new Date(date)).toBeLessThan(1000 * 60 * 60 * 24 * 30 * 12 * 10);
};

const parsed = await parser.parseString(response.text);
Expand Down
12 changes: 7 additions & 5 deletions test/utils/rand-user-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ describe('rand-user-agent', () => {
});

it('should match ua configurated', async () => {
const response1 = await got('https://httpbingo.org/user-agent');
expect(response1.data['user-agent']).toBe(config.ua);
nock('https://rsshub.test')
.get('/test')
.reply(function () {
return [200, { ua: this.req.headers['user-agent'] }];
});

const response2 = await got('https://httpbingo.org/user-agent', {
const resonse = await got('https://rsshub.test/test', {
headers: {
'user-agent': mobileUa,
},
});
expect(response2.data['user-agent']).toBe(mobileUa);
expect(response2.data['user-agent']).not.toBe(config.ua);
expect(resonse.data.ua).toBe(mobileUa);
});
});
5 changes: 5 additions & 0 deletions website/src/components/InstanceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export default function InstanceList(): JSX.Element {
location: '🇺🇸',
maintainer: '思维悦动',
maintainerUrl: 'https://friesport.ac.cn',
}, {
url: 'https://rsshub.atgw.io',
location: '🇺🇸',
maintainer: 'limfoo',
maintainerUrl: 'https://blog.limfoo.io',
}]

return (
Expand Down

0 comments on commit fe5f104

Please sign in to comment.