-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clients(devtools): escape assets based on filetype #8456
Conversation
build/build-dt-report-resources.js
Outdated
/** @type {string} */ | ||
let prefix; | ||
if (name.endsWith('.html')) { | ||
// This will not support unicode characters in inline stylesheets or js. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to do something about this then?
might be better to throw if we detect this case instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There actually isn't any non ascii characters in the HTML files (afaik). This is just for (semi) completeness.
How would you detect nonascii in a style rule (and not elsewhere in the html)? I'm ok with just deferring this until there is nonascii in these files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you detect nonascii in a style rule (and not elsewhere in the html)?
seems like it doesn't matter since we don't have any right now? It does seem better to just throw and be explicit about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can throw on any ascii. Cannot allow ascii in html but throw on ascii in style/script (w/o actually parsing). I'll do the former.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can throw on any ascii.
that's what I was at least trying to say :)
build/build-dt-report-resources.js
Outdated
@@ -23,8 +23,20 @@ const htmlReportAssets = require('../lighthouse-core/report/html/html-report-ass | |||
*/ | |||
function convertToAsciiAndWriteFile(name, content) { | |||
assert(content); | |||
|
|||
/** @type {string} */ | |||
let prefix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unicodeEscapePrefix
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity, why does this have to be ascii? Seems really 20th century for Chrome asset loading
build/build-dt-report-resources.js
Outdated
// eslint-disable-next-line no-control-regex | ||
const escaped = content.replace(/[^\x00-\x7F]/g, c => '\\\\u' + c.charCodeAt(0).toString(16)); | ||
|
||
/** @type {string} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if going to declare this as a string
, maybe give it \\\\u
as the default (instead of doing it in the final else
) and then override it if html or css
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
build/build-dt-report-resources.js
Outdated
/** @type {string} */ | ||
let prefix; | ||
if (name.endsWith('.html')) { | ||
// This will not support unicode characters in inline stylesheets or js. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you detect nonascii in a style rule (and not elsewhere in the html)?
seems like it doesn't matter since we don't have any right now? It does seem better to just throw and be explicit about it
Aye. is there something we can fix on the DT side to avoid this? |
Maybe. Can look into it post-5.0. |
What currently happens with our emdash without this escaping? (just curious where the error is) Instead of this escaping route, could we change the character in the
|
Without the context-specific escaping: It was mistakenly escaped with \u{...}. It showed up as a literal "\u{...}". With no escaping: devtools build errors.
Yes. Confirmed it's just the dash.
|
build/build-dt-report-resources.js
Outdated
/** @type {string} */ | ||
let prefix; | ||
if (name.endsWith('.html')) { | ||
// This will not support unicode characters in inline stylesheets or js. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can throw on any ascii.
that's what I was at least trying to say :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(though it seemed like you were agreeing with @paulirish before on just escaping it where we use it instead?)
I think we should keep it as unescaped in the source (for readability) and just make this small build tweak. Hopefully this whole thing goes away if devtools' build process can be updated. |
SGTM |
Co-Authored-By: Hoten <cjamcl@gmail.com>
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
Was tripped up by https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/report/html/report-styles.css#L738