@@ -25,14 +25,16 @@ const OBJECT_PROPERTY_PATTERN =
2525
2626/** Values that are encoded payloads (inline images, fonts), not readable data. */
2727const MAX_UNBROKEN_VALUE_LENGTH = 200
28- const BASE64_PAYLOAD_PATTERN = / ^ [ A - Z a - z 0 - 9 + / ] { 20 , } = { 0 , 2 } $ /
28+ const BASE64_ALPHABET_PATTERN = / ^ [ A - Z a - z 0 - 9 + / ] { 24 , } = { 0 , 2 } $ /
2929
3030/**
31- * A string literal (kept, so a `//` inside `'https://…'` survives) or a comment
32- * (dropped, so commented-out records never read as page data).
31+ * A string literal (kept, so a `//` inside `'https://…'` survives), a regex
32+ * literal (kept, so the `//` ending `/https?:\/\//` survives; recognized only
33+ * where an expression can start, so division is not mistaken for one), or a
34+ * comment (dropped, so commented-out records never read as page data).
3335 */
3436const STRING_OR_COMMENT_PATTERN =
35- / ( " (?: [ ^ " \\ \r \n ] | \\ .) * " | ' (?: [ ^ ' \\ \r \n ] | \\ .) * ' | ` (?: [ ^ ` \\ ] | \\ .) * ` ) | \/ \/ [ ^ \r \n ] * | \/ \* [ \s \S ] * ?\* \/ / g
37+ / ( " (?: [ ^ " \\ \r \n ] | \\ .) * " | ' (?: [ ^ ' \\ \r \n ] | \\ .) * ' | ` (?: [ ^ ` \\ ] | \\ .) * ` | \/ (?< = (?: ^ | [ = ( , : ; ! & | ? { } [ \] + \- * % ~ ^ < > ] | \b r e t u r n ) \s * \/ ) (? ! [ * / ] ) (?: [ ^ / \\ \r \n [ ] | \\ . | \[ (?: [ ^ \] \\ \r \n ] | \\ . ) * \] ) + \/ [ a - z ] * ) | \/ \/ [ ^ \r \n ] * | \/ \* [ \s \S ] * ?\* \/ / g
3638
3739/**
3840 * Whether a rendered `view` body may hold an Optics HTML macro, whose text only
@@ -145,10 +147,20 @@ function readScriptData(script: string): string {
145147}
146148
147149function isReadableValue ( value : string ) : boolean {
148- if ( ! value || value . startsWith ( 'data:' ) || BASE64_PAYLOAD_PATTERN . test ( value ) ) return false
150+ if ( ! value || value . startsWith ( 'data:' ) || isBase64Payload ( value ) ) return false
149151 return value . length <= MAX_UNBROKEN_VALUE_LENGTH || / \s / . test ( value )
150152}
151153
154+ /**
155+ * Base64-alphabet runs that also carry the evidence of encoding: padding or
156+ * `+`/`/`, or the upper, lower, and digit mix random bytes produce. A long name
157+ * (`MicrosoftAuthenticationLibrary`) or numeric id has the alphabet but not this.
158+ */
159+ function isBase64Payload ( value : string ) : boolean {
160+ if ( ! BASE64_ALPHABET_PATTERN . test ( value ) ) return false
161+ return / [ + / = ] / . test ( value ) || ( / [ a - z ] / . test ( value ) && / [ A - Z ] / . test ( value ) && / \d / . test ( value ) )
162+ }
163+
152164const JS_ESCAPES : Record < string , string > = { n : ' ' , r : ' ' , t : ' ' , b : '' , f : '' , v : '' }
153165
154166function unescapeJsString ( value : string ) : string {
0 commit comments