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
fix(ui): escape html for console log view #4724
Conversation
✅ Deploy Preview for fastidious-cascaron-4ded94 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
export function escapeHtml(unsafe: string) { | ||
return unsafe | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
} |
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.
It might be worth noting that the similar code is also used for junit xml.
vitest/packages/vitest/src/node/reporters/junit.ts
Lines 54 to 64 in d0c3a1f
function escapeXML(value: any): string { | |
return removeInvalidXMLCharacters( | |
String(value) | |
.replace(/&/g, '&') | |
.replace(/"/g, '"') | |
.replace(/'/g, ''') | |
.replace(/</g, '<') | |
.replace(/>/g, '>'), | |
true, | |
) | |
} |
Is it preferred to move this into @vitest/utils
and share everywhere?
// https://github.com/vitest-dev/vitest/issues/2765 | ||
it('regexp', () => { | ||
console.log(/(?<char>\w)/) | ||
}) | ||
|
||
// https://github.com/vitest-dev/vitest/issues/3934 | ||
it('html-raw', async () => { | ||
console.log(` | ||
<form> | ||
<label for="email">Email Address</label> | ||
<input name="email" /> | ||
<button>Submit</button> | ||
</form> | ||
`); | ||
}) | ||
|
||
// https://github.com/vitest-dev/vitest/issues/1279 | ||
it('html-pretty', () => { | ||
const div = document.createElement("div"); | ||
div.innerHTML = ` | ||
<form> | ||
<label for="email">Email Address</label> | ||
<input name="email" /> | ||
<button>Submit</button> | ||
</form> | ||
`.replaceAll(/\n */gm, ""); // strip new liens | ||
console.log(prettyDOM(div)) | ||
}) |
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 add e2e tests 64ae9d2. Asserting dom format was difficult, so the actual testing is limited to only checking /(?<char>\w)
string.
Thank you! Let's try this out. |
Description
Closes #1279, #2765, #3934
I'm not sure if this naive idea is supposed to work (or already attempted before) but this is just to start investigation and I will test it further.
At least this
filter.toHtml(escapeHtml(...))
pattern seems to be already used in report view:vitest/packages/ui/client/components/views/ViewReport.vue
Line 39 in 4a32fdc
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.