File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -7,15 +7,17 @@ const MAX_CONCURRENT_REQUESTS = 10;
77
88function 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
Original file line number Diff line number Diff line change @@ -7,15 +7,17 @@ const MAX_CONCURRENT_REQUESTS = 10;
77
88function 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
You can’t perform that action at this time.
0 commit comments