self::MAX_INPUT_BYTES ) { throw new InvalidArgumentException( 'manual_comment_too_large' ); } $comment = wp_check_invalid_utf8( $comment, true ); $comment = sanitize_textarea_field( $comment ); $comment = (string) preg_replace( '/-----BEGIN [^-]{1,80}PRIVATE KEY-----[\s\S]*?(?:-----END [^-]{1,80}PRIVATE KEY-----|$)/iu', '[private-key-redacted]', $comment ); $comment = (string) preg_replace( '/\b(?:password|passwd|pwd|secret|token|authorization|api[ _-]?key)\b\s*[:=]\s*[^\s,;]+/iu', '[credential-redacted]', $comment ); $comment = (string) preg_replace( '#https?://[^\s<>]+#iu', '[url-redacted]', $comment ); $comment = (string) preg_replace( '/\b[A-Z0-9._%+\-]+@[A-Z0-9.\-]+\.[A-Z]{2,}\b/iu', '[email-redacted]', $comment ); $comment = (string) preg_replace( '/(?utf8_prefix( $comment, self::MAX_STORED_BYTES ); } private function utf8_prefix( string $value, int $maximum ): string { if ( strlen( $value ) <= $maximum ) { return $value; } $value = substr( $value, 0, $maximum ); while ( '' !== $value && 1 !== preg_match( '//u', $value ) ) { $value = substr( $value, 0, -1 ); } return rtrim( $value ); } }