|
130 | 130 | formatExportFunction: function() { |
131 | 131 | var tableData = this.logsData; |
132 | 132 | 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 | + |
133 | 171 | for (var i = 0; i < tableData.length; i++) { |
134 | 172 | var item = {}; |
135 | 173 | item[CV.i18n('logger.requests').toUpperCase()] = countlyCommon.formatTimeAgoText(tableData[i].reqts).text; |
|
152 | 190 | } |
153 | 191 | if (tableData[i].q) { |
154 | 192 | 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); |
156 | 194 | } |
157 | 195 | catch (err) { |
158 | 196 | item[CV.i18n('logger.request-header').toUpperCase()] = "-"; |
159 | 197 | } |
160 | 198 | } |
161 | 199 | if (tableData[i].h) { |
162 | 200 | try { |
163 | | - var stringifiedHeader = JSON.stringify(tableData[i].h); |
164 | | - item["REQUEST HEADER"] = stringifiedHeader.replace(/"/g, '"'); |
| 201 | + item["REQUEST HEADER"] = sanitizeQueryData(tableData[i].h); |
165 | 202 | } |
166 | 203 | catch (err) { |
167 | 204 | item["REQUEST HEADER"] = "-"; |
|
0 commit comments