Skip to content

Commit

Permalink
feat(property): now can match more new properties and add to results …
Browse files Browse the repository at this point in the history
…if it is possible
  • Loading branch information
dalisoft committed Oct 18, 2021
1 parent f9487ab commit d9a9bb6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/finders/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ export default function caseRequestModeFinder(
if (res !== undefined) {
return res;
}

if (_key && res !== null) {
return {
link: _key,
linked: false,
line_index: index,
key: _key,
mode: 'property'
};
}
} else {
// Method matching
const reqIndex = line.indexOf('req');
Expand Down
4 changes: 2 additions & 2 deletions src/finders/request/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function requestMethodFinder(
_key: string,
line: string,
index: number
): IBlock | void {
): IBlock | null | void {
let key;
let link;
const extracted = variableKeyExtractor(line);
Expand All @@ -29,7 +29,7 @@ export default function requestMethodFinder(
}
if (_key.includes('getMethod(') || _key.includes('getUrl(')) {
// uWebSockets.js has native `getMethod` and `getUrl` support
return undefined;
return null;
}
if (
(_key === 'req;' || _key === 'request;') &&
Expand Down
15 changes: 15 additions & 0 deletions tests/analyze.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ describe('property parse', () => {
}
]);
});
it('req.ip', () => {
expect(
analyze((request, response) => {
response.end(request.ip);
})
).toEqual([
{
key: 'ip',
line_index: 1,
link: 'ip',
linked: false,
mode: 'property'
}
]);
});
});

describe('request property parse', () => {
Expand Down

0 comments on commit d9a9bb6

Please sign in to comment.