Skip to content

Commit 6b09ce6

Browse files
Merge pull request #157 from SingularityNET-Archive:development
refactor: Improve sanitizeObject function to handle additional quote types and whitespace characters
2 parents c9bb92b + d4783b1 commit 6b09ce6

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

netlify/functions/batchUpdateMeetingSummariesArray.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ const MAX_CONCURRENT_REQUESTS = 10;
77

88
function sanitizeObject(item) {
99
if (typeof item === 'string') {
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
10+
1511
return item
16-
.replace(/\r?\n/g, ' ')
17-
.replace(/[\u2013\u2014]/g, '-')
18-
.replace(/[\u2018\u2019]/g, "'")
19-
.replace(/[\u201C\u201D]/g, '"')
20-
.replace(/"/g, '\\"')
12+
.replace(/\r?\n/g, ' ') // Remove newlines
13+
.replace(/[\u2013\u2014\u2015]/g, '-') // Handle en dash, em dash, and horizontal bar
14+
.replace(/[\u2018\u2019\u201A\u201B\u2032\u2035]/g, "'") // Handle various single quotes
15+
.replace(/[\u201C\u201D\u201E\u201F\u2033\u2036]/g, '"') // Handle various double quotes
16+
.replace(/[\u2026]/g, '...') // Handle ellipsis
17+
.replace(/[\u00A0]/g, ' ') // Replace non-breaking space with regular space
2118
.trim();
2219
}
23-
20+
2421
if (Array.isArray(item)) {
2522
return item.map(element => sanitizeObject(element));
2623
}
27-
24+
2825
if (item && typeof item === 'object') {
2926
const newObj = {};
3027
for (const key in item) {
@@ -33,7 +30,7 @@ function sanitizeObject(item) {
3330
return newObj;
3431
}
3532

36-
// For numbers, booleans, null, etc., return as is
33+
// for numbers, booleans, null, etc just return item.
3734
return item;
3835
}
3936

netlify/functions/batchUpdateMeetingSummariesById.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ const MAX_CONCURRENT_REQUESTS = 10;
77

88
function sanitizeObject(item) {
99
if (typeof item === 'string') {
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
10+
1511
return item
16-
.replace(/\r?\n/g, ' ')
17-
.replace(/[\u2013\u2014]/g, '-')
18-
.replace(/[\u2018\u2019]/g, "'")
19-
.replace(/[\u201C\u201D]/g, '"')
20-
.replace(/"/g, '\\"')
12+
.replace(/\r?\n/g, ' ') // Remove newlines
13+
.replace(/[\u2013\u2014\u2015]/g, '-') // Handle en dash, em dash, and horizontal bar
14+
.replace(/[\u2018\u2019\u201A\u201B\u2032\u2035]/g, "'") // Handle various single quotes
15+
.replace(/[\u201C\u201D\u201E\u201F\u2033\u2036]/g, '"') // Handle various double quotes
16+
.replace(/[\u2026]/g, '...') // Handle ellipsis
17+
.replace(/[\u00A0]/g, ' ') // Replace non-breaking space with regular space
2118
.trim();
22-
}
19+
}
2320

2421
if (Array.isArray(item)) {
2522
return item.map(element => sanitizeObject(element));
@@ -37,7 +34,6 @@ function sanitizeObject(item) {
3734
return item;
3835
}
3936

40-
4137
async function fetchMeetingSummaries(lastProcessedTimestamp, batchNumber) {
4238
const { data: summaries, error } = await supabase
4339
.from('meetingsummaries')

0 commit comments

Comments
 (0)