File tree 3 files changed +34
-1
lines changed 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ unreleased
4
4
* Add ` options ` argument to ` req.range `
5
5
- Includes the ` combine ` option
6
6
* Fix Windows absolute path check using forward slashes
7
+ * Improve error with invalid arguments to ` req.get() `
7
8
* Improve performance for ` res.json ` /` res.jsonp ` in most cases
8
9
* deps: accepts@~ 1.3.3
9
10
- Fix including type extensions in parameters in ` Accept ` parsing
Original file line number Diff line number Diff line change @@ -57,6 +57,14 @@ var req = exports = module.exports = {
57
57
58
58
req . get =
59
59
req . header = function header ( name ) {
60
+ if ( ! name ) {
61
+ throw new TypeError ( 'name argument is required to req.get' ) ;
62
+ }
63
+
64
+ if ( typeof name !== 'string' ) {
65
+ throw new TypeError ( 'name must be a string to req.get' ) ;
66
+ }
67
+
60
68
var lc = name . toLowerCase ( ) ;
61
69
62
70
switch ( lc ) {
Original file line number Diff line number Diff line change @@ -31,5 +31,29 @@ describe('req', function(){
31
31
. set ( 'Referrer' , 'http://foobar.com' )
32
32
. expect ( 'http://foobar.com' , done ) ;
33
33
} )
34
+
35
+ it ( 'should throw missing header name' , function ( done ) {
36
+ var app = express ( )
37
+
38
+ app . use ( function ( req , res ) {
39
+ res . end ( req . get ( ) )
40
+ } )
41
+
42
+ request ( app )
43
+ . get ( '/' )
44
+ . expect ( 500 , / T y p e E r r o r : n a m e a r g u m e n t i s r e q u i r e d t o r e q .g e t / , done )
45
+ } )
46
+
47
+ it ( 'should throw for non-string header name' , function ( done ) {
48
+ var app = express ( )
49
+
50
+ app . use ( function ( req , res ) {
51
+ res . end ( req . get ( 42 ) )
52
+ } )
53
+
54
+ request ( app )
55
+ . get ( '/' )
56
+ . expect ( 500 , / T y p e E r r o r : n a m e m u s t b e a s t r i n g t o r e q .g e t / , done )
57
+ } )
34
58
} )
35
- } )
59
+ } )
You can’t perform that action at this time.
0 commit comments