File tree 2 files changed +29
-4
lines changed
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -429,7 +429,7 @@ Command.setReplyTransformer("hgetall", function (result) {
429
429
for ( let i = 0 ; i < result . length ; i += 2 ) {
430
430
const key = result [ i ] ;
431
431
const value = result [ i + 1 ] ;
432
- if ( obj [ key ] ) {
432
+ if ( key in obj ) {
433
433
// can only be truthy if the property is special somehow, like '__proto__' or 'constructor'
434
434
// https://github.com/luin/ioredis/issues/1267
435
435
Object . defineProperty ( obj , key , {
Original file line number Diff line number Diff line change 1
1
import Redis from "../../lib/redis" ;
2
2
import { expect } from "chai" ;
3
3
4
+ const CUSTOM_PROPERTY = "_myCustomProperty" ;
5
+
4
6
describe ( "hgetall" , function ( ) {
5
- it ( "should handle __proto__" , async function ( ) {
7
+ beforeEach ( function ( ) {
8
+ Object . defineProperty ( Object . prototype , CUSTOM_PROPERTY , {
9
+ value : false ,
10
+ configurable : true ,
11
+ enumerable : false ,
12
+ writable : false ,
13
+ } ) ;
14
+ } ) ;
15
+
16
+ afterEach ( function ( ) {
17
+ delete ( Object . prototype as any ) [ CUSTOM_PROPERTY ] ;
18
+ } ) ;
19
+
20
+ it ( "should handle special field names" , async function ( ) {
6
21
const redis = new Redis ( ) ;
7
- await redis . hset ( "test_key" , "__proto__" , "hello" ) ;
22
+ await redis . hmset (
23
+ "test_key" ,
24
+ "__proto__" ,
25
+ "hello" ,
26
+ CUSTOM_PROPERTY ,
27
+ "world"
28
+ ) ;
8
29
const ret = await redis . hgetall ( "test_key" ) ;
9
30
expect ( ret . __proto__ ) . to . eql ( "hello" ) ;
10
- expect ( Object . keys ( ret ) ) . to . eql ( [ "__proto__" ] ) ;
31
+ expect ( ret [ CUSTOM_PROPERTY ] ) . to . eql ( "world" ) ;
32
+ expect ( Object . keys ( ret ) . sort ( ) ) . to . eql (
33
+ [ "__proto__" , CUSTOM_PROPERTY ] . sort ( )
34
+ ) ;
35
+ expect ( Object . getPrototypeOf ( ret ) ) . to . eql ( Object . prototype ) ;
11
36
} ) ;
12
37
} ) ;
You can’t perform that action at this time.
0 commit comments