Skip to content

Commit 2869110

Browse files
committed
[fix] double encoding issue
1 parent 92eb7e5 commit 2869110

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

plugins/logger/frontend/public/javascripts/countly.views.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,44 @@
130130
formatExportFunction: function() {
131131
var tableData = this.logsData;
132132
var table = [];
133+
var sanitizeQueryData = function(data) {
134+
try {
135+
// If data is already a string, parse it first
136+
let queryObject = typeof data === 'string' ? JSON.parse(data) : data;
137+
138+
// Handle nested JSON strings within the object
139+
Object.keys(queryObject).forEach(key => {
140+
if (typeof queryObject[key] === 'string') {
141+
// Try to parse if it looks like JSON
142+
if (queryObject[key].startsWith('{') || queryObject[key].startsWith('[')) {
143+
try {
144+
queryObject[key] = JSON.parse(queryObject[key]);
145+
if (typeof queryObject[key] === 'object' && queryObject[key] !== null) {
146+
queryObject[key] = sanitizeQueryData(queryObject[key]);
147+
}
148+
}
149+
catch (e) {
150+
// If parsing fails, keep decoded string
151+
}
152+
}
153+
queryObject[key] = countlyCommon.unescapeHtml(queryObject[key]);
154+
}
155+
else if (typeof queryObject[key] === 'object' && queryObject[key] !== null) {
156+
// Recursively handle nested objects
157+
Object.keys(queryObject[key]).forEach(nestedKey => {
158+
if (typeof queryObject[key][nestedKey] === 'string') {
159+
queryObject[key][nestedKey] = countlyCommon.unescapeHtml(queryObject[key][nestedKey]);
160+
}
161+
});
162+
}
163+
});
164+
return JSON.stringify(queryObject);
165+
}
166+
catch (err) {
167+
return data; // Return original data if processing fails
168+
}
169+
};
170+
133171
for (var i = 0; i < tableData.length; i++) {
134172
var item = {};
135173
item[CV.i18n('logger.requests').toUpperCase()] = countlyCommon.formatTimeAgoText(tableData[i].reqts).text;
@@ -152,16 +190,15 @@
152190
}
153191
if (tableData[i].q) {
154192
try {
155-
item[CV.i18n('logger.request-query').toUpperCase()] = JSON.stringify(tableData[i].q);
193+
item[CV.i18n('logger.request-query').toUpperCase()] = sanitizeQueryData(tableData[i].q);
156194
}
157195
catch (err) {
158196
item[CV.i18n('logger.request-header').toUpperCase()] = "-";
159197
}
160198
}
161199
if (tableData[i].h) {
162200
try {
163-
var stringifiedHeader = JSON.stringify(tableData[i].h);
164-
item["REQUEST HEADER"] = stringifiedHeader.replace(/&quot;/g, '"');
201+
item["REQUEST HEADER"] = sanitizeQueryData(tableData[i].h);
165202
}
166203
catch (err) {
167204
item["REQUEST HEADER"] = "-";

0 commit comments

Comments
 (0)