@@ -58,7 +58,7 @@ async function translate(language: string, filePath: string) {
5858
5959 parser . on ( "text" , text => {
6060 if ( isRecording ) {
61- currentSegment += ` ${ text } ` ;
61+ currentSegment += strongEscapeXML ( text ) ;
6262 } else {
6363 segments . push ( [ false , text ] ) ;
6464 }
@@ -140,7 +140,7 @@ async function translate(language: string, filePath: string) {
140140
141141 clean . on ( "text" , text => {
142142 if ( currDepth >= 1 ) {
143- translated += escapeXML ( text ) ;
143+ translated += strongEscapeXML ( text ) ;
144144 }
145145 } ) ;
146146
@@ -209,7 +209,7 @@ async function translate(language: string, filePath: string) {
209209 const text = messageContent . text ;
210210 // console.log(text.value);
211211
212- const safeText = escapeXML ( text . value ) ;
212+ const safeText : String = escapeXML ( text . value ) ;
213213 const textStream = Readable . from ( "<WRAPPER>" + safeText + "</WRAPPER>" ) ;
214214
215215 await new Promise < void > ( ( resolve , reject ) => {
@@ -238,3 +238,14 @@ function formatAttributes(attrs) {
238238function escapeXML ( str : string ) : string {
239239 return str . replace ( / & (? ! (?: a m p ; | l t ; | g t ; | a p o s ; | q u o t ; ) ) / g, "&" ) ;
240240}
241+
242+
243+
244+ function strongEscapeXML ( str : string ) : string {
245+ return str
246+ . replace ( / & (? ! (?: a m p ; | l t ; | g t ; | a p o s ; | q u o t ; ) ) / g, "&" )
247+ . replace ( / < / g, "<" )
248+ . replace ( / > / g, ">" )
249+ . replace ( / " / g, """ )
250+ . replace ( / ' / g, "'" ) ;
251+ }
0 commit comments