Skip to content

Commit e41be0c

Browse files
fixed escaped characters when importing
1 parent f53b55a commit e41be0c

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

import.php

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77

8+
// This mess could need some cleanup!
89
if (isset($_POST['commands'])) {
910
$commands = explode("\n", $_POST['commands']);
1011

@@ -22,6 +23,8 @@
2223
// We can't just explode since we might have \" inside the key. So do a preg_split on " with a negative lookbehind assertions to make sure it isn't a \".
2324
$key = preg_split('/(?<!\\\\)"/', substr($command[1], 1), 2);
2425

26+
$key[0] = stripslashes($key[0]);
27+
2528
// Strip the seperating space
2629
$key[1] = substr($key[1], 1);
2730
} else {
@@ -30,48 +33,81 @@
3033

3134
switch ($command[0]) {
3235
case 'SET': {
33-
// Trim the optional "" acount th value.
34-
$redis->set($key[0], trim($key[1], '"'));
36+
if ($key[1][0] == '"') {
37+
$val = stripslashes(trim($key[1], '"'));
38+
} else {
39+
$val = $key[1];
40+
}
41+
42+
$redis->set($key[0], $val);
3543
break;
3644
}
3745

3846
case 'HSET': {
3947
if ($key[1][0] == '"') {
4048
// See preg_split above.
4149
$hkey = preg_split('/(?<!\\\\)"/', substr($key[1], 1), 2);
50+
51+
$hkey[0] = stripslashes($hkey[0]);
4252

4353
// Strip the seperating space
4454
$hkey[1] = substr($hkey[1], 1);
4555
} else {
4656
$hkey = explode(' ', $key[1], 2);
4757
}
4858

49-
$redis->hSet($key[0], $hkey[0], trim($hkey[1], '"'));
59+
if ($hkey[1][0] == '"') {
60+
$val = stripslashes(trim($hkey[1], '"'));
61+
} else {
62+
$val = $hkey[1];
63+
}
64+
65+
$redis->hSet($key[0], $hkey[0], $val);
5066
break;
5167
}
5268

5369
case 'RPUSH': {
54-
$redis->rPush($key[0], trim($key[1], '"'));
70+
if ($key[1][0] == '"') {
71+
$val = stripslashes(trim($key[1], '"'));
72+
} else {
73+
$val = $key[1];
74+
}
75+
76+
$redis->rPush($key[0], $val);
5577
break;
5678
}
5779

5880
case 'SADD': {
59-
$redis->sAdd($key[0], trim($key[1], '"'));
81+
if ($key[1][0] == '"') {
82+
$val = stripslashes(trim($key[1], '"'));
83+
} else {
84+
$val = $key[1];
85+
}
86+
87+
$redis->sAdd($key[0], $val);
6088
break;
6189
}
6290

6391
case 'ZADD': {
6492
if ($key[1][0] == '"') {
6593
// See preg_split ebove.
6694
$score = preg_split('/(?<!\\\\)"/', substr($key[1], 1), 2);
95+
96+
$score[0] = stripslashes($score[0]);
6797

6898
// Strip the seperating space
6999
$score[1] = substr($score[1], 1);
70100
} else {
71101
$score = explode(' ', $key[1], 2);
72102
}
73103

74-
$redis->zAdd($key[0], $score[0], trim($score[1], '"'));
104+
if ($score[1][0] == '"') {
105+
$val = stripslashes(trim($score[1], '"'));
106+
} else {
107+
$val = $score[1];
108+
}
109+
110+
$redis->zAdd($key[0], $score[0], $val);
75111
break;
76112
}
77113

@@ -80,7 +116,6 @@
80116
}
81117

82118

83-
84119
// Refresh the top so the key tree is updated.
85120
require 'header.inc.php';
86121

0 commit comments

Comments
 (0)