@@ -37,6 +37,9 @@ export const oddRowClassName = 'vscode-codeql__result-table-row--odd';
3737export const pathRowClassName = 'vscode-codeql__result-table-row--path' ;
3838export const selectedRowClassName = 'vscode-codeql__result-table-row--selected' ;
3939
40+ const CONTROL_CODE = '\u001F' . codePointAt ( 0 ) ! ;
41+ const CONTROL_LABEL = '\u2400' . codePointAt ( 0 ) ! ;
42+
4043export function jumpToLocationHandler (
4144 loc : ResolvableLocationValue ,
4245 databaseUri : string ,
@@ -67,24 +70,42 @@ export function openFile(filePath: string): void {
6770 } ) ;
6871}
6972
73+ function convertedNonprintableChars ( label : string ) {
74+ // If the label was empty, use a placeholder instead, so the link is still clickable.
75+ if ( ! label ) {
76+ return '[empty string]' ;
77+ } else if ( label . match ( / ^ \s + $ / ) ) {
78+ return `[whitespace: "${ label } "]` ;
79+ } else {
80+ /**
81+ * If the label contains certain non-printable characters, loop through each
82+ * character and replace it with the cooresponding unicode control label.
83+ */
84+ const convertedLabelArray : any [ ] = [ ] ;
85+ for ( let i = 0 ; i < label . length ; i ++ ) {
86+ const labelCheck = label . codePointAt ( i ) ! ;
87+ if ( labelCheck <= CONTROL_CODE ) {
88+ convertedLabelArray [ i ] = String . fromCodePoint ( labelCheck + CONTROL_LABEL ) ;
89+ } else {
90+ convertedLabelArray [ i ] = label . charAt ( i ) ;
91+ }
92+ }
93+ return convertedLabelArray . join ( '' ) ;
94+ }
95+ }
96+
7097/**
7198 * Render a location as a link which when clicked displays the original location.
7299 */
73100export function renderLocation (
74- loc : UrlValue | undefined ,
75- label : string | undefined ,
76- databaseUri : string ,
101+ loc ? : UrlValue ,
102+ label ? : string ,
103+ databaseUri ? : string ,
77104 title ?: string ,
78105 callback ?: ( ) => void
79106) : JSX . Element {
80107
81- // If the label was empty, use a placeholder instead, so the link is still clickable.
82- let displayLabel = label ;
83- if ( ! label ) {
84- displayLabel = '[empty string]' ;
85- } else if ( label . match ( / ^ \s + $ / ) ) {
86- displayLabel = `[whitespace: "${ label } "]` ;
87- }
108+ const displayLabel = convertedNonprintableChars ( label ! ) ;
88109
89110 if ( loc === undefined ) {
90111 return < span > { displayLabel } </ span > ;
@@ -93,7 +114,7 @@ export function renderLocation(
93114 }
94115
95116 const resolvableLoc = tryGetResolvableLocation ( loc ) ;
96- if ( resolvableLoc !== undefined ) {
117+ if ( databaseUri !== undefined && resolvableLoc !== undefined ) {
97118 return (
98119 < a href = "#"
99120 className = "vscode-codeql__result-table-location-link"
0 commit comments