From 4783ad6bff74080c0f606fe88d03863f379dbf91 Mon Sep 17 00:00:00 2001 From: marcnjaramillo Date: Tue, 5 Oct 2021 19:37:14 -0700 Subject: [PATCH 1/6] Create rough solution for handling non-printing characters in results --- .../ql-vscode/src/view/RawTableValue.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/extensions/ql-vscode/src/view/RawTableValue.tsx b/extensions/ql-vscode/src/view/RawTableValue.tsx index 013715c1531..59746454d1b 100644 --- a/extensions/ql-vscode/src/view/RawTableValue.tsx +++ b/extensions/ql-vscode/src/view/RawTableValue.tsx @@ -10,12 +10,28 @@ interface Props { export default function RawTableValue(props: Props): JSX.Element { const v = props.value; + const codes: { [key: string]: any } = { + '\n': 'U+000A', + '\b': 'U+2084', + '\0': 'U+0000' + }; + if ( typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' ) { - return {v.toString()}; + const text = v.toString(); + const newVal = text.split(''); + for (let i = 0; i < newVal.length; i++) { + for (const char in codes) { + if (char === newVal[i]) { + newVal[i] = codes[char]; + } + } + } + const cleanVal = newVal.join(''); + return {cleanVal}; } return renderLocation(v.url, v.label, props.databaseUri); From 2f7d175a769135c6923484bb0f404f9a7d75e092 Mon Sep 17 00:00:00 2001 From: marcnjaramillo Date: Wed, 6 Oct 2021 14:01:39 -0700 Subject: [PATCH 2/6] Make edits per feedback --- .../ql-vscode/src/view/RawTableValue.tsx | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/extensions/ql-vscode/src/view/RawTableValue.tsx b/extensions/ql-vscode/src/view/RawTableValue.tsx index 59746454d1b..188b471ba42 100644 --- a/extensions/ql-vscode/src/view/RawTableValue.tsx +++ b/extensions/ql-vscode/src/view/RawTableValue.tsx @@ -8,31 +8,31 @@ interface Props { databaseUri: string; } +const codes: { [key: string]: any } = { + '\0': 'U+0000', + '\b': 'U+0008', + '\t': 'U+0009', + '\n': 'U+000A', + '\v': 'U+000B', + '\r': 'U+000D' +}; + export default function RawTableValue(props: Props): JSX.Element { - const v = props.value; - const codes: { [key: string]: any } = { - '\n': 'U+000A', - '\b': 'U+2084', - '\0': 'U+0000' - }; + const rawValue = props.value; if ( - typeof v === 'string' - || typeof v === 'number' - || typeof v === 'boolean' + typeof rawValue === 'string' + || typeof rawValue === 'number' + || typeof rawValue === 'boolean' ) { - const text = v.toString(); + const text = rawValue.toString(); const newVal = text.split(''); for (let i = 0; i < newVal.length; i++) { - for (const char in codes) { - if (char === newVal[i]) { - newVal[i] = codes[char]; - } - } + newVal[i] = codes[newVal[i]] || newVal[i]; } const cleanVal = newVal.join(''); return {cleanVal}; } - return renderLocation(v.url, v.label, props.databaseUri); + return renderLocation(rawValue.url, rawValue.label, props.databaseUri); } From 245db7ca28dd99c5f7054c832af21936e2394c89 Mon Sep 17 00:00:00 2001 From: marcnjaramillo Date: Thu, 7 Oct 2021 09:09:48 -0700 Subject: [PATCH 3/6] Add a check for strings with only new line chars --- .../ql-vscode/src/view/RawTableValue.tsx | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/extensions/ql-vscode/src/view/RawTableValue.tsx b/extensions/ql-vscode/src/view/RawTableValue.tsx index 188b471ba42..d0fa4d3c591 100644 --- a/extensions/ql-vscode/src/view/RawTableValue.tsx +++ b/extensions/ql-vscode/src/view/RawTableValue.tsx @@ -12,11 +12,14 @@ const codes: { [key: string]: any } = { '\0': 'U+0000', '\b': 'U+0008', '\t': 'U+0009', - '\n': 'U+000A', '\v': 'U+000B', '\r': 'U+000D' }; +function onlyNewLine(element: string, index: number, array: string[]) { + return element === '\n'; +} + export default function RawTableValue(props: Props): JSX.Element { const rawValue = props.value; @@ -26,12 +29,17 @@ export default function RawTableValue(props: Props): JSX.Element { || typeof rawValue === 'boolean' ) { const text = rawValue.toString(); - const newVal = text.split(''); - for (let i = 0; i < newVal.length; i++) { - newVal[i] = codes[newVal[i]] || newVal[i]; + const newVal = text.split('').filter((element: string) => element !== ' '); + if (newVal.every(onlyNewLine)) { + const cleanVal = '[' + newVal.join('') + ']'; + return {cleanVal}; + } else { + for (let i = 0; i < newVal.length; i++) { + newVal[i] = codes[newVal[i]] || newVal[i]; + } + const cleanVal = newVal.join(''); + return {cleanVal}; } - const cleanVal = newVal.join(''); - return {cleanVal}; } return renderLocation(rawValue.url, rawValue.label, props.databaseUri); From d1eb31e231112dc2da6093eb5feec00480b6bea4 Mon Sep 17 00:00:00 2001 From: marcnjaramillo Date: Fri, 8 Oct 2021 12:56:56 -0700 Subject: [PATCH 4/6] Finish creating check for non-printing characters --- .../ql-vscode/src/view/RawTableValue.tsx | 26 +---------- .../ql-vscode/src/view/result-table-utils.tsx | 43 ++++++++++++++----- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/extensions/ql-vscode/src/view/RawTableValue.tsx b/extensions/ql-vscode/src/view/RawTableValue.tsx index d0fa4d3c591..5f3ee9fa7f4 100644 --- a/extensions/ql-vscode/src/view/RawTableValue.tsx +++ b/extensions/ql-vscode/src/view/RawTableValue.tsx @@ -8,38 +8,14 @@ interface Props { databaseUri: string; } -const codes: { [key: string]: any } = { - '\0': 'U+0000', - '\b': 'U+0008', - '\t': 'U+0009', - '\v': 'U+000B', - '\r': 'U+000D' -}; - -function onlyNewLine(element: string, index: number, array: string[]) { - return element === '\n'; -} - export default function RawTableValue(props: Props): JSX.Element { const rawValue = props.value; - if ( typeof rawValue === 'string' || typeof rawValue === 'number' || typeof rawValue === 'boolean' ) { - const text = rawValue.toString(); - const newVal = text.split('').filter((element: string) => element !== ' '); - if (newVal.every(onlyNewLine)) { - const cleanVal = '[' + newVal.join('') + ']'; - return {cleanVal}; - } else { - for (let i = 0; i < newVal.length; i++) { - newVal[i] = codes[newVal[i]] || newVal[i]; - } - const cleanVal = newVal.join(''); - return {cleanVal}; - } + return {renderLocation(undefined, rawValue.toString())}; } return renderLocation(rawValue.url, rawValue.label, props.databaseUri); diff --git a/extensions/ql-vscode/src/view/result-table-utils.tsx b/extensions/ql-vscode/src/view/result-table-utils.tsx index 64bb10564f7..a96edd3e051 100644 --- a/extensions/ql-vscode/src/view/result-table-utils.tsx +++ b/extensions/ql-vscode/src/view/result-table-utils.tsx @@ -37,6 +37,9 @@ export const oddRowClassName = 'vscode-codeql__result-table-row--odd'; export const pathRowClassName = 'vscode-codeql__result-table-row--path'; export const selectedRowClassName = 'vscode-codeql__result-table-row--selected'; +const CONTROL_CODE = '\u001F'.codePointAt(0)!; +const CONTROL_LABEL = '\u2400'.codePointAt(0)!; + export function jumpToLocationHandler( loc: ResolvableLocationValue, databaseUri: string, @@ -67,24 +70,42 @@ export function openFile(filePath: string): void { }); } +function convertedNonprintableChars(label: string) { + // If the label was empty, use a placeholder instead, so the link is still clickable. + if (!label) { + return '[empty string]'; + } else if (label.match(/^\s+$/)) { + return `[whitespace: "${label}"]`; + } else { + /** + * If the label contains certain non-printable characters, loop through each + * character and replace it with the cooresponding unicode control label. + */ + const convertedLabelArray: any[] = []; + for (let i = 0; i < label.length; i++) { + const labelCheck = label.codePointAt(i)!; + if (labelCheck <= CONTROL_CODE) { + convertedLabelArray[i] = String.fromCodePoint(labelCheck + CONTROL_LABEL); + } else { + convertedLabelArray[i] = label.charAt(i); + } + } + return convertedLabelArray.join(''); + } +} + /** * Render a location as a link which when clicked displays the original location. */ export function renderLocation( - loc: UrlValue | undefined, - label: string | undefined, - databaseUri: string, + loc?: UrlValue, + label?: string, + databaseUri?: string, title?: string, callback?: () => void ): JSX.Element { - // If the label was empty, use a placeholder instead, so the link is still clickable. - let displayLabel = label; - if (!label) { - displayLabel = '[empty string]'; - } else if (label.match(/^\s+$/)) { - displayLabel = `[whitespace: "${label}"]`; - } + const displayLabel = convertedNonprintableChars(label!); if (loc === undefined) { return {displayLabel}; @@ -93,7 +114,7 @@ export function renderLocation( } const resolvableLoc = tryGetResolvableLocation(loc); - if (resolvableLoc !== undefined) { + if (databaseUri !== undefined && resolvableLoc !== undefined) { return ( Date: Fri, 8 Oct 2021 13:05:48 -0700 Subject: [PATCH 5/6] Add changes to changelog --- extensions/ql-vscode/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 6ccc6abf46e..4148f26f513 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -2,6 +2,8 @@ ## [UNRELEASED] +- Add a check to make sure certain control codes (U+0000 - U+001F) are detected and replaced with their cooresponding control labels (0x2400) in the results view. [#963](https://github.com/github/vscode-codeql/pull/963) + ## 1.5.6 - 07 October 2021 - Add progress messages to LGTM download option. This makes the two-step process (selecting a project, then selecting a language) more clear. [#960](https://github.com/github/vscode-codeql/pull/960) From b43b824da636429074b11ed7b0380d04644d46a4 Mon Sep 17 00:00:00 2001 From: Marc Jaramillo Date: Fri, 8 Oct 2021 13:52:07 -0700 Subject: [PATCH 6/6] Simplify changelog entry Co-authored-by: Andrew Eisenberg --- extensions/ql-vscode/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 4148f26f513..6bd2a2ca832 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -2,7 +2,7 @@ ## [UNRELEASED] -- Add a check to make sure certain control codes (U+0000 - U+001F) are detected and replaced with their cooresponding control labels (0x2400) in the results view. [#963](https://github.com/github/vscode-codeql/pull/963) +- Replace certain control codes (`U+0000` - `U+001F`) with their corresponding control labels (`U+2400` - `U+241F`) in the results view. [#963](https://github.com/github/vscode-codeql/pull/963) ## 1.5.6 - 07 October 2021