Skip to content
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

Merged
merged 4 commits into from
Apr 25, 2019

Conversation

connorjclark
Copy link
Collaborator

/** @type {string} */
let prefix;
if (name.endsWith('.html')) {
// This will not support unicode characters in inline stylesheets or js.
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Member

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

Copy link
Collaborator Author

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.

Copy link
Member

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 :)

@@ -23,8 +23,20 @@ const htmlReportAssets = require('../lighthouse-core/report/html/html-report-ass
*/
function convertToAsciiAndWriteFile(name, content) {
assert(content);

/** @type {string} */
let prefix;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unicodeEscapePrefix maybe?

Copy link
Member

@brendankenny brendankenny left a 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

// eslint-disable-next-line no-control-regex
const escaped = content.replace(/[^\x00-\x7F]/g, c => '\\\\u' + c.charCodeAt(0).toString(16));

/** @type {string} */
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

/** @type {string} */
let prefix;
if (name.endsWith('.html')) {
// This will not support unicode characters in inline stylesheets or js.
Copy link
Member

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

@paulirish
Copy link
Member

out of curiosity, why does this have to be ascii? Seems really 20th century for Chrome asset loading

Aye. is there something we can fix on the DT side to avoid this?

@connorjclark
Copy link
Collaborator Author

Maybe. Can look into it post-5.0.

@paulirish
Copy link
Member

paulirish commented Apr 22, 2019

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 content property... just use the unicode escape instead.. https://stackoverflow.com/a/190412/89484 ?

content: '\2014'

@connorjclark
Copy link
Collaborator Author

connorjclark commented Apr 22, 2019

What currently happens with our emdash without this escaping? (just curious where the error is)

Without the context-specific escaping: It was mistakenly escaped with \u{...}. It showed up as a literal "\u{...}".

With no escaping: devtools build errors.

Instead of this escaping route, could we change the character in the content property... just use the unicode escape instead.. stackoverflow.com/a/190412/89484 ?

content: '\2014'

Yes.

Confirmed it's just the dash.

report.js
≤
©
►
▼
…
…
├
─
─
├
─
─
├
─
─
├
─
─
└
─
─
└
─
─
├
─
─
└
─
─
├
─
─
├
─
─
├
─
─
…
⋮
report.css
—
template.html
templates.html

build/build-dt-report-resources.js Outdated Show resolved Hide resolved
/** @type {string} */
let prefix;
if (name.endsWith('.html')) {
// This will not support unicode characters in inline stylesheets or js.
Copy link
Member

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 :)

Copy link
Member

@brendankenny brendankenny left a 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?)

@connorjclark
Copy link
Collaborator Author

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.

@brendankenny
Copy link
Member

SGTM

Co-Authored-By: Hoten <cjamcl@gmail.com>
@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants