Skip to content

Commit c9bb92b

Browse files
Merge pull request #156 from SingularityNET-Archive:development
refactor: Enhance sanitizeObject function to escape double quotes for valid JSON
2 parents 297fd59 + 8cd360e commit c9bb92b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

netlify/functions/batchUpdateMeetingSummariesArray.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ const MAX_CONCURRENT_REQUESTS = 10;
77

88
function sanitizeObject(item) {
99
if (typeof item === 'string') {
10-
// Replace line breaks with spaces
11-
// Only replace en dash (U+2013) or em dash (U+2014) with ASCII hyphen '-'
12-
// Replace curly single quotes ’ and ‘ with straight ASCII apostrophe '
13-
// Replace curly double quotes ” and “ with straight ASCII quote "
10+
// 1. Remove line breaks
11+
// 2. Replace fancy dashes with '-'
12+
// 3. Replace curly single quotes ’ and ‘ with straight apostrophe '
13+
// 4. Replace curly double quotes ” and “ with straight ASCII quote "
14+
// 5. Escape any new " characters to \" for valid JSON
1415
return item
1516
.replace(/\r?\n/g, ' ')
1617
.replace(/[\u2013\u2014]/g, '-')
1718
.replace(/[\u2018\u2019]/g, "'")
1819
.replace(/[\u201C\u201D]/g, '"')
20+
.replace(/"/g, '\\"')
1921
.trim();
2022
}
2123

netlify/functions/batchUpdateMeetingSummariesById.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ const MAX_CONCURRENT_REQUESTS = 10;
77

88
function sanitizeObject(item) {
99
if (typeof item === 'string') {
10-
// Replace line breaks with spaces
11-
// Only replace en dash (U+2013) or em dash (U+2014) with ASCII hyphen '-'
12-
// Replace curly single quotes ’ and ‘ with straight ASCII apostrophe '
13-
// Replace curly double quotes ” and “ with straight ASCII quote "
10+
// 1. Remove line breaks
11+
// 2. Replace fancy dashes with '-'
12+
// 3. Replace curly single quotes ’ and ‘ with straight apostrophe '
13+
// 4. Replace curly double quotes ” and “ with straight ASCII quote "
14+
// 5. Escape any new " characters to \" for valid JSON
1415
return item
1516
.replace(/\r?\n/g, ' ')
1617
.replace(/[\u2013\u2014]/g, '-')
1718
.replace(/[\u2018\u2019]/g, "'")
1819
.replace(/[\u201C\u201D]/g, '"')
20+
.replace(/"/g, '\\"')
1921
.trim();
2022
}
2123

0 commit comments

Comments
 (0)