mirror of
https://github.com/expressjs/express.git
synced 2026-02-26 18:57:43 +00:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4007ad103b | ||
|
|
2f64f68c37 | ||
|
|
ed0ba3f1dc | ||
|
|
8eace4603c | ||
|
|
30bae81027 | ||
|
|
758d4355d4 | ||
|
|
77bcd5274a | ||
|
|
f33caf1f89 | ||
|
|
54af593b73 | ||
|
|
2551a7d8af | ||
|
|
4453d83cca | ||
|
|
db507669ca | ||
|
|
374fc1a0f9 | ||
|
|
1b196c8b82 | ||
|
|
64e7373d69 | ||
|
|
e4fb370ad8 | ||
|
|
60d4c16cc9 | ||
|
|
9e6760e186 | ||
|
|
ffa89f2ccf | ||
|
|
b9b9f52b2f | ||
|
|
9a7afb2886 | ||
|
|
2eb42059f3 | ||
|
|
aa907945cd | ||
|
|
89f198c6a5 | ||
|
|
d9a62f9833 |
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@@ -27,11 +27,11 @@ jobs:
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
|
||||
@@ -46,19 +46,19 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
node-version: [18, 19, 20, 21, 22, 23, 24]
|
||||
node-version: [18, 19, 20, 21, 22, 23, 24, 25]
|
||||
# Node.js release schedule: https://nodejs.org/en/about/releases/
|
||||
|
||||
name: Node.js ${{ matrix.node-version }} - ${{matrix.os}}
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
@@ -80,7 +80,7 @@ jobs:
|
||||
run: npm run test-ci
|
||||
|
||||
- name: Upload code coverage
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: coverage-node-${{ matrix.node-version }}-${{ matrix.os }}
|
||||
path: ./coverage/lcov.info
|
||||
@@ -93,7 +93,7 @@ jobs:
|
||||
contents: read
|
||||
checks: write
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
@@ -102,7 +102,7 @@ jobs:
|
||||
run: sudo apt-get -y install lcov
|
||||
|
||||
- name: Collect coverage reports
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||
with:
|
||||
path: ./coverage
|
||||
pattern: coverage-node-*
|
||||
@@ -112,6 +112,6 @@ jobs:
|
||||
run: find ./coverage -name lcov.info -exec printf '-a %q\n' {} \; | xargs lcov -o ./lcov.info
|
||||
|
||||
- name: Upload coverage report
|
||||
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6
|
||||
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7
|
||||
with:
|
||||
file: ./lcov.info
|
||||
|
||||
6
.github/workflows/codeql.yml
vendored
6
.github/workflows/codeql.yml
vendored
@@ -39,13 +39,13 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
|
||||
uses: github/codeql-action/init@fe4161a26a8629af62121b670040955b330f9af2 # v3.29.5
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
config: |
|
||||
@@ -71,4 +71,4 @@ jobs:
|
||||
# ./location_of_script_within_repo/buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
|
||||
uses: github/codeql-action/analyze@fe4161a26a8629af62121b670040955b330f9af2 # v3.29.5
|
||||
|
||||
12
.github/workflows/legacy.yml
vendored
12
.github/workflows/legacy.yml
vendored
@@ -37,12 +37,12 @@ jobs:
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
@@ -64,7 +64,7 @@ jobs:
|
||||
run: npm run test-ci
|
||||
|
||||
- name: Upload code coverage
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: coverage-node-${{ matrix.node-version }}-${{ matrix.os }}
|
||||
path: ./coverage/lcov.info
|
||||
@@ -77,7 +77,7 @@ jobs:
|
||||
contents: read
|
||||
checks: write
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
@@ -86,7 +86,7 @@ jobs:
|
||||
run: sudo apt-get -y install lcov
|
||||
|
||||
- name: Collect coverage reports
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||
with:
|
||||
path: ./coverage
|
||||
pattern: coverage-node-*
|
||||
@@ -96,6 +96,6 @@ jobs:
|
||||
run: find ./coverage -name lcov.info -exec printf '-a %q\n' {} \; | xargs lcov -o ./lcov.info
|
||||
|
||||
- name: Upload coverage report
|
||||
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6
|
||||
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7
|
||||
with:
|
||||
file: ./lcov.info
|
||||
|
||||
8
.github/workflows/scorecard.yml
vendored
8
.github/workflows/scorecard.yml
vendored
@@ -32,12 +32,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
|
||||
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
@@ -59,7 +59,7 @@ jobs:
|
||||
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||
# format to the repository Actions tab.
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
@@ -67,6 +67,6 @@ jobs:
|
||||
|
||||
# Upload the results to GitHub's code scanning dashboard.
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
|
||||
uses: github/codeql-action/upload-sarif@fe4161a26a8629af62121b670040955b330f9af2 # v3.29.5
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -5,6 +5,10 @@ npm-shrinkwrap.json
|
||||
*.log
|
||||
*.gz
|
||||
|
||||
# Yarn
|
||||
yarn-error.log
|
||||
yarn.lock
|
||||
|
||||
# Coveralls
|
||||
.nyc_output
|
||||
coverage
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
5.2.0 / 2025-12-01
|
||||
========================
|
||||
|
||||
* Security fix for [CVE-2024-51999](https://www.cve.org/CVERecord?id=CVE-2024-51999) ([GHSA-pj86-cfqh-vqx6](https://github.com/expressjs/express/security/advisories/GHSA-pj86-cfqh-vqx6))
|
||||
* deps: `body-parser@^2.2.1`
|
||||
* A deprecation warning was added when using `res.redirect` with undefined arguments, Express now emits a warning to help detect calls that pass undefined as the status or URL and make them easier to fix.
|
||||
|
||||
5.1.0 / 2025-03-31
|
||||
========================
|
||||
|
||||
|
||||
21
Readme.md
21
Readme.md
@@ -40,7 +40,9 @@ app.get('/', (req, res) => {
|
||||
res.send('Hello World')
|
||||
})
|
||||
|
||||
app.listen(3000)
|
||||
app.listen(3000, () => {
|
||||
console.log('Server is running on http://localhost:3000')
|
||||
})
|
||||
```
|
||||
|
||||
## Installation
|
||||
@@ -206,13 +208,11 @@ The original author of Express is [TJ Holowaychuk](https://github.com/tj)
|
||||
* [bjohansebas](https://github.com/bjohansebas) - **Sebastian Beltran**
|
||||
* [carpasse](https://github.com/carpasse) - **Carlos Serrano**
|
||||
* [CBID2](https://github.com/CBID2) - **Christine Belzie**
|
||||
* [dpopp07](https://github.com/dpopp07) - **Dustin Popp**
|
||||
* [UlisesGascon](https://github.com/UlisesGascon) - **Ulises Gascón** (he/him)
|
||||
* [3imed-jaberi](https://github.com/3imed-jaberi) - **Imed Jaberi**
|
||||
* [IamLizu](https://github.com/IamLizu) - **S M Mahmudul Hasan** (he/him)
|
||||
* [Phillip9587](https://github.com/Phillip9587) - **Phillip Barta**
|
||||
* [Sushmeet](https://github.com/Sushmeet) - **Sushmeet Sunger**
|
||||
* [rxmarbles](https://github.com/rxmarbles) **Rick Markins** (He/him)
|
||||
* [efekrskl](https://github.com/efekrskl) - **Efe Karasakal**
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Triagers emeriti members</summary>
|
||||
@@ -251,6 +251,9 @@ The original author of Express is [TJ Holowaychuk](https://github.com/tj)
|
||||
* [dakshkhetan](https://github.com/dakshkhetan) - **Daksh Khetan** (he/him)
|
||||
* [lucasraziel](https://github.com/lucasraziel) - **Lucas Soares Do Rego**
|
||||
* [mertcanaltin](https://github.com/mertcanaltin) - **Mert Can Altin**
|
||||
* [dpopp07](https://github.com/dpopp07) - **Dustin Popp**
|
||||
* [Sushmeet](https://github.com/Sushmeet) - **Sushmeet Sunger**
|
||||
* [3imed-jaberi](https://github.com/3imed-jaberi) - **Imed Jaberi**
|
||||
|
||||
</details>
|
||||
|
||||
@@ -259,14 +262,14 @@ The original author of Express is [TJ Holowaychuk](https://github.com/tj)
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
[coveralls-image]: https://badgen.net/coveralls/c/github/expressjs/express/master
|
||||
[coveralls-image]: https://img.shields.io/coverallsCoverage/github/expressjs/express?branch=master
|
||||
[coveralls-url]: https://coveralls.io/r/expressjs/express?branch=master
|
||||
[github-actions-ci-image]: https://badgen.net/github/checks/expressjs/express/master?label=CI
|
||||
[github-actions-ci-image]: https://img.shields.io/github/actions/workflow/status/expressjs/express/ci.yml?branch=master&label=ci
|
||||
[github-actions-ci-url]: https://github.com/expressjs/express/actions/workflows/ci.yml
|
||||
[npm-downloads-image]: https://badgen.net/npm/dm/express
|
||||
[npm-downloads-image]: https://img.shields.io/npm/dm/express
|
||||
[npm-downloads-url]: https://npmcharts.com/compare/express?minimal=true
|
||||
[npm-url]: https://npmjs.org/package/express
|
||||
[npm-version-image]: https://badgen.net/npm/v/express
|
||||
[npm-version-image]: https://img.shields.io/npm/v/express
|
||||
[ossf-scorecard-badge]: https://api.scorecard.dev/projects/github.com/expressjs/express/badge
|
||||
[ossf-scorecard-visualizer]: https://ossf.github.io/scorecard-visualizer/#/projects/github.com/expressjs/express
|
||||
[Code of Conduct]: https://github.com/expressjs/.github/blob/HEAD/CODE_OF_CONDUCT.md
|
||||
|
||||
@@ -597,7 +597,7 @@ app.render = function render(name, options, callback) {
|
||||
|
||||
app.listen = function listen() {
|
||||
var server = http.createServer(this)
|
||||
var args = Array.prototype.slice.call(arguments)
|
||||
var args = slice.call(arguments)
|
||||
if (typeof args[args.length - 1] === 'function') {
|
||||
var done = args[args.length - 1] = once(args[args.length - 1])
|
||||
server.once('error', done)
|
||||
|
||||
@@ -282,12 +282,12 @@ req.is = function is(types) {
|
||||
*/
|
||||
|
||||
defineGetter(req, 'protocol', function protocol(){
|
||||
var proto = this.connection.encrypted
|
||||
var proto = this.socket.encrypted
|
||||
? 'https'
|
||||
: 'http';
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
|
||||
if (!trust(this.connection.remoteAddress, 0)) {
|
||||
if (!trust(this.socket.remoteAddress, 0)) {
|
||||
return proto;
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ defineGetter(req, 'host', function host(){
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
var val = this.get('X-Forwarded-Host');
|
||||
|
||||
if (!val || !trust(this.connection.remoteAddress, 0)) {
|
||||
if (!val || !trust(this.socket.remoteAddress, 0)) {
|
||||
val = this.get('Host');
|
||||
} else if (val.indexOf(',') !== -1) {
|
||||
// Note: X-Forwarded-Host is normally only ever a
|
||||
|
||||
@@ -266,6 +266,6 @@ function createETagGenerator (options) {
|
||||
|
||||
function parseExtendedQueryString(str) {
|
||||
return qs.parse(str, {
|
||||
allowPrototypes: true
|
||||
plainObjects: true
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "express",
|
||||
"description": "Fast, unopinionated, minimalist web framework",
|
||||
"version": "5.1.0",
|
||||
"version": "5.2.0",
|
||||
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
||||
"contributors": [
|
||||
"Aaron Heckmann <aaron.heckmann+github@gmail.com>",
|
||||
@@ -33,7 +33,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"accepts": "^2.0.0",
|
||||
"body-parser": "^2.2.0",
|
||||
"body-parser": "^2.2.1",
|
||||
"content-disposition": "^1.0.0",
|
||||
"content-type": "^1.0.5",
|
||||
"cookie": "^0.7.1",
|
||||
@@ -84,7 +84,6 @@
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"History.md",
|
||||
"Readme.md",
|
||||
"index.js",
|
||||
"lib/"
|
||||
|
||||
@@ -39,7 +39,7 @@ describe('req', function(){
|
||||
app.enable('trust proxy');
|
||||
|
||||
app.use(function(req, res){
|
||||
req.connection.encrypted = true;
|
||||
req.socket.encrypted = true;
|
||||
res.end(req.protocol);
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
var assert = require('node:assert')
|
||||
var express = require('../')
|
||||
, request = require('supertest');
|
||||
var qs = require('qs');
|
||||
|
||||
describe('req', function(){
|
||||
describe('.query', function(){
|
||||
@@ -38,6 +39,22 @@ describe('req', function(){
|
||||
.get('/?user.name=tj')
|
||||
.expect(200, '{"user.name":"tj"}', done);
|
||||
});
|
||||
|
||||
it('should not be able to access object prototype properties', function (done) {
|
||||
var app = createApp('extended', true);
|
||||
|
||||
request(app)
|
||||
.get('/?foo=yee')
|
||||
.expect(200, /TypeError: req\.query\.hasOwnProperty is not a function/, done);
|
||||
});
|
||||
|
||||
it('should be able to use object prototype property names as keys', function (done) {
|
||||
var app = createApp('extended', true);
|
||||
|
||||
request(app)
|
||||
.get('/?hasOwnProperty=yee')
|
||||
.expect(200, '{"query":{"hasOwnProperty":"yee"},"error":"TypeError: req.query.hasOwnProperty is not a function"}', done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when "query parser" is simple', function () {
|
||||
@@ -48,6 +65,22 @@ describe('req', function(){
|
||||
.get('/?user%5Bname%5D=tj')
|
||||
.expect(200, '{"user[name]":"tj"}', done);
|
||||
});
|
||||
|
||||
it('should not be able to access object prototype properties', function (done) {
|
||||
var app = createApp('simple', true);
|
||||
|
||||
request(app)
|
||||
.get('/?foo=yee')
|
||||
.expect(200, /TypeError: req\.query\.hasOwnProperty is not a function/, done);
|
||||
});
|
||||
|
||||
it('should be able to use object prototype property names as keys', function (done) {
|
||||
var app = createApp('simple', true);
|
||||
|
||||
request(app)
|
||||
.get('/?hasOwnProperty=yee')
|
||||
.expect(200, '{"query":{"hasOwnProperty":"yee"},"error":"TypeError: req.query.hasOwnProperty is not a function"}', done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when "query parser" is a function', function () {
|
||||
@@ -60,6 +93,18 @@ describe('req', function(){
|
||||
.get('/?user%5Bname%5D=tj')
|
||||
.expect(200, '{"length":17}', done);
|
||||
});
|
||||
|
||||
// test exists to verify behavior for folks wishing to workaround our qs defaults
|
||||
it('should drop object prototype property names and be able to access object prototype properties', function (done) {
|
||||
var app = createApp(
|
||||
function (str) {
|
||||
return qs.parse(str)
|
||||
}, true);
|
||||
|
||||
request(app)
|
||||
.get('/?hasOwnProperty=biscuits')
|
||||
.expect(200, '{"query":{},"hasOwnProperty":false}', done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when "query parser" disabled', function () {
|
||||
@@ -70,6 +115,22 @@ describe('req', function(){
|
||||
.get('/?user%5Bname%5D=tj')
|
||||
.expect(200, '{}', done);
|
||||
});
|
||||
|
||||
it('should not be able to access object prototype properties', function (done) {
|
||||
var app = createApp('extended', true);
|
||||
|
||||
request(app)
|
||||
.get('/?foo=yee')
|
||||
.expect(200, /TypeError: req\.query\.hasOwnProperty is not a function/, done);
|
||||
});
|
||||
|
||||
it('should be able to use object prototype property names as keys', function (done) {
|
||||
var app = createApp('extended', true);
|
||||
|
||||
request(app)
|
||||
.get('/?hasOwnProperty=yee')
|
||||
.expect(200, '{"query":{"hasOwnProperty":"yee"},"error":"TypeError: req.query.hasOwnProperty is not a function"}', done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when "query parser" enabled', function () {
|
||||
@@ -80,6 +141,22 @@ describe('req', function(){
|
||||
.get('/?user%5Bname%5D=tj')
|
||||
.expect(200, '{"user[name]":"tj"}', done);
|
||||
});
|
||||
|
||||
it('should not be able to access object prototype properties', function (done) {
|
||||
var app = createApp('extended', true);
|
||||
|
||||
request(app)
|
||||
.get('/?foo=yee')
|
||||
.expect(200, /TypeError: req\.query\.hasOwnProperty is not a function/, done);
|
||||
});
|
||||
|
||||
it('should be able to use object prototype property names as keys', function (done) {
|
||||
var app = createApp('extended', true);
|
||||
|
||||
request(app)
|
||||
.get('/?hasOwnProperty=yee')
|
||||
.expect(200, '{"query":{"hasOwnProperty":"yee"},"error":"TypeError: req.query.hasOwnProperty is not a function"}', done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when "query parser" an unknown value', function () {
|
||||
@@ -91,7 +168,7 @@ describe('req', function(){
|
||||
})
|
||||
})
|
||||
|
||||
function createApp(setting) {
|
||||
function createApp(setting, isPrototypePropertyTest) {
|
||||
var app = express();
|
||||
|
||||
if (setting !== undefined) {
|
||||
@@ -99,7 +176,17 @@ function createApp(setting) {
|
||||
}
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.send(req.query);
|
||||
if(isPrototypePropertyTest) {
|
||||
try {
|
||||
var hasOwnProperty = req.query.hasOwnProperty('✨ express ✨');
|
||||
res.send({ query: req.query, hasOwnProperty: hasOwnProperty });
|
||||
} catch (error) {
|
||||
res.send({ query: req.query, error: error.toString() });
|
||||
}
|
||||
}
|
||||
else {
|
||||
res.send(req.query);
|
||||
}
|
||||
});
|
||||
|
||||
return app;
|
||||
|
||||
Reference in New Issue
Block a user