Skip to content

Commit cff43dd

Browse files
Merge pull request #4059 from RedisInsight/fe/feature/PR-4025
check PR 4025
2 parents ec9fcfe + 554d3af commit cff43dd

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

redisinsight/ui/src/utils/formatters/valueFormatters.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const formattingBuffer = (
9696
}
9797
case KeyValueFormat.PHP: {
9898
try {
99-
const decoded = unserialize(Buffer.from(reply.data), {}, { strict: false, encoding: 'binary' })
99+
const decoded = unserialize(bufferToUTF8(reply), {}, { strict: false, encoding: 'utf8' })
100100
const value = JSONBigInt.stringify(decoded)
101101
return JSONViewer({ value, ...props })
102102
} catch (e) {
@@ -216,7 +216,7 @@ const bufferToSerializedFormat = (
216216
}
217217
case KeyValueFormat.PHP: {
218218
try {
219-
const decoded = unserialize(Buffer.from(value.data), {}, { strict: false, encoding: 'binary' })
219+
const decoded = unserialize(bufferToUTF8(value), {}, { strict: false, encoding: 'utf8' })
220220
const stringified = JSON.stringify(decoded)
221221
return reSerializeJSON(stringified, space)
222222
} catch (e) {

redisinsight/ui/src/utils/tests/formatters/valueFormatters.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('bufferToSerializedFormat', () => {
9494

9595
describe(KeyValueFormat.PHP, () => {
9696
describe('should properly serialize', () => {
97-
const testValues = [[1], '""', 6677, true, { a: { b: [1, 2, '3'] } }].map((v) => ({
97+
const testValues = [[1], '""', '反序列化', 6677, true, { a: { b: [1, 2, '3'] } }].map((v) => ({
9898
input: stringToBuffer(serialize(v)),
9999
expected: JSON.stringify(v)
100100
}))
@@ -156,7 +156,7 @@ describe('stringToSerializedBufferFormat', () => {
156156

157157
describe(KeyValueFormat.PHP, () => {
158158
describe('should properly unserialize', () => {
159-
const testValues = [[1], '""', 6677, true, { a: { b: [1, 2, '3'] } }].map((v) => ({
159+
const testValues = [[1], '""', '反序列化', 6677, true, { a: { b: [1, 2, '3'] } }].map((v) => ({
160160
input: JSON.stringify(v),
161161
expected: stringToBuffer(serialize(v))
162162
}))
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { rte } from '../../../../helpers/constants';
2+
import { populateHashWithFields } from '../../../../helpers/keys';
3+
import { Common, DatabaseHelper } from '../../../../helpers';
4+
import { BrowserPage } from '../../../../pageObjects';
5+
import {
6+
commonUrl,
7+
ossStandaloneV8Config
8+
} from '../../../../helpers/conf';
9+
import { DatabaseAPIRequests } from '../../../../helpers/api/api-database';
10+
import { APIKeyRequests } from '../../../../helpers/api/api-keys';
11+
const apiKeyRequests = new APIKeyRequests();
12+
13+
14+
const browserPage = new BrowserPage();
15+
const databaseHelper = new DatabaseHelper();
16+
const databaseAPIRequests = new DatabaseAPIRequests();
17+
18+
const keyName = `TestHashKey-${ Common.generateWord(10) }`;
19+
const keyToAddParameters = { fieldsCount: 1, keyName, fieldStartWith: 'hashField', fieldValueStartWith: 'hashValue' };
20+
21+
fixture `Formatters`
22+
.meta({
23+
type: 'regression',
24+
rte: rte.standalone
25+
})
26+
.page(commonUrl)
27+
.beforeEach(async() => {
28+
await databaseHelper.acceptLicenseTermsAndAddDatabaseApi(ossStandaloneV8Config);
29+
30+
await populateHashWithFields(ossStandaloneV8Config.host, ossStandaloneV8Config.port, keyToAddParameters);
31+
})
32+
.afterEach(async() => {
33+
// Clear keys and database
34+
await apiKeyRequests.deleteKeyByNameApi(keyName, ossStandaloneV8Config.databaseName);
35+
await databaseAPIRequests.deleteStandaloneDatabaseApi(ossStandaloneV8Config);
36+
});
37+
38+
test.before(async t => {
39+
await databaseHelper.acceptLicenseTermsAndAddDatabaseApi(ossStandaloneV8Config);
40+
41+
})('Verify that UTF8 in PHP serialized', async t => {
42+
const phpValueChinese = '测试';
43+
const phpValueCRussian = 'Привет мир!';
44+
const setValue =`SET ${keyName} "a:3:{s:4:\\"name\\";s:6:\\"${phpValueChinese}\\";s:3:\\"age\\";i:30;s:7:\\"message\\";s:20:\\"${phpValueCRussian}\\";}"\n`;
45+
46+
await browserPage.Cli.sendCommandInCli(setValue);
47+
await t.click(browserPage.refreshKeysButton);
48+
49+
await browserPage.openKeyDetailsByKeyName(keyName);
50+
await browserPage.selectFormatter('PHP serialized');
51+
await t.expect(await browserPage.getStringKeyValue()).contains(phpValueChinese, 'data is not serialized in php');
52+
await t.expect(await browserPage.getStringKeyValue()).contains(phpValueCRussian, 'data is not serialized in php');
53+
});

0 commit comments

Comments
 (0)