@@ -168,6 +168,9 @@ function log(message, trace) {
168168}
169169
170170async function processError ( e ) {
171+ if ( ! ( e instanceof Error ) ) {
172+ return String ( e ) ;
173+ }
171174 let text = e . message ;
172175 if ( e instanceof HTTPError ) {
173176 const response = e . response ;
@@ -206,6 +209,8 @@ async function processError(e) {
206209 target='_blank'>GitHub personal access token</a> to your <a href='/user'>profile</a>
207210 or else use 'View on GitHub'.` ;
208211 }
212+ } else if ( e . cause ) {
213+ text += `<br>This error is caused by:<br>${ await processError ( e . cause ) } ` ;
209214 }
210215 return text ;
211216}
@@ -420,14 +425,17 @@ function loadObject(key) {
420425 return JSON . parse ( value_ ) ;
421426}
422427
423- function escapeHtml ( unsafe ) {
424- return unsafe
425- . replace ( / & / g, "&" )
426- . replace ( / < / g, "<" )
427- . replace ( / > / g, ">" )
428- . replace ( / " / g, """ )
429- . replace ( / ' / g, "'" )
430- . replace ( / \n / g, "<br>" ) ;
428+ // Escapes &, <, >, ", ' — idempotently
429+ function escapeHtml ( input ) {
430+ return (
431+ String ( input )
432+ // & → & (but skip existing entities like & < { 💩)
433+ . replace ( / & (? ! # \d + ; | # x [ 0 - 9 A - F a - f ] + ; | \w + ; ) / g, "&" )
434+ . replace ( / < / g, "<" )
435+ . replace ( / > / g, ">" )
436+ . replace ( / " / g, """ )
437+ . replace ( / ' / g, "'" )
438+ ) ;
431439}
432440
433441function handleSortingTables ( ) {
@@ -687,3 +695,15 @@ function isClassicPAT(token) {
687695 const pattern = / ^ g h p _ [ a - z A - Z 0 - 9 ] { 36 } $ / ;
688696 return token . match ( pattern ) != null ;
689697}
698+
699+ function htmlToText ( html ) {
700+ const htmlViewer = document . createElement ( "div" ) ;
701+ // FF can use overflow:hidden but Safari on iPad does not render it
702+ htmlViewer . textCSS =
703+ "height:0;position:fixed;top:0;font-size:xx-small;opacity:0;" ;
704+ document . body . prepend ( htmlViewer ) ;
705+ htmlViewer . innerHTML = html ;
706+ const text = htmlViewer . innerText ;
707+ htmlViewer . remove ( ) ;
708+ return text ;
709+ }
0 commit comments