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

Handle nonprint chars #963

Merged
merged 8 commits into from
Oct 8, 2021
Merged

Conversation

marcnjaramillo
Copy link
Contributor

Resolves #584

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • @github/docs-content-codeql has been cc'd in all issues for UI or other user-facing changes made by this pull request.

Comment on lines 13 to 17
const codes: { [key: string]: any } = {
'\n': 'U+000A',
'\b': 'U+2084',
'\0': 'U+0000'
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this out of the function to the module level scope? This way, the constant doesn't need to be recreated on each invocation.

Copy link
Contributor

Choose a reason for hiding this comment

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

And presumably, you will be able to add more replacements in the future?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can explicitly add all of the control char mappings described here #584 (comment).

if (
typeof v === 'string'
|| typeof v === 'number'
|| typeof v === 'boolean'
) {
return <span>{v.toString()}</span>;
const text = v.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big fan of one char variable names. Can you rename it to something like rawValue. I know this code was already, but it's never too late to make improvements. :)

Comment on lines 27 to 31
for (const char in codes) {
if (char === newVal[i]) {
newVal[i] = codes[char];
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There's something simpler you can do here. You don't need to loop.

Suggested change
for (const char in codes) {
if (char === newVal[i]) {
newVal[i] = codes[char];
}
}
newVal[i] = codes[newVal[i]] || newVal[i];

@marcnjaramillo marcnjaramillo marked this pull request as ready for review October 8, 2021 20:04
@marcnjaramillo marcnjaramillo requested a review from a team as a code owner October 8, 2021 20:04
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

Small suggestion about the change log and then 🚢 .

extensions/ql-vscode/CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Andrew Eisenberg <[email protected]>
@aeisenberg aeisenberg merged commit 81a2f9c into github:main Oct 8, 2021
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.

Problems handling non-printable chars
3 participants