Skip to content

Commit dee53b7

Browse files
fix special characters in hyperlink in ag grid (#11962)
1 parent 1f77195 commit dee53b7

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

app/gui/src/project-view/components/visualizations/TableVisualization.vue

+12-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@/components/visualizations/TableVisualization/tableVizToolbar'
88
import { Ast } from '@/util/ast'
99
import { Pattern } from '@/util/ast/match'
10+
import { LINKABLE_URL_REGEX } from '@/util/link'
1011
import { useVisualizationConfig } from '@/util/visualizationBuiltins'
1112
import type {
1213
CellClassParams,
@@ -197,7 +198,8 @@ function formatText(params: ICellRendererParams) {
197198
.replaceAll('>', '>')
198199
199200
if (textFormatterSelected.value === 'off') {
200-
return htmlEscaped.replace(/^\s+|\s+$/g, ' ')
201+
const replaceLinks = replaceLinksWithTag(htmlEscaped)
202+
return replaceLinks.replace(/^\s+|\s+$/g, ' ')
201203
}
202204
203205
const partialMappings = {
@@ -218,10 +220,7 @@ function formatText(params: ICellRendererParams) {
218220
return `<span style="color: #df8800">${match.replaceAll(' ', '&#183;')}</span>`
219221
})
220222
221-
const replaceLinks = replaceSpaces.replace(
222-
/https?:\/\/([-()_.!~*';/?:@&=+$,A-Za-z0-9])+/g,
223-
(url: string) => `<a href="${url}" target="_blank" class="link">${url}</a>`,
224-
)
223+
const replaceLinks = replaceLinksWithTag(replaceSpaces)
225224
226225
const replaceReturns = replaceLinks.replace(
227226
/\r\n/g,
@@ -251,6 +250,13 @@ function setRowLimit(newRowLimit: number) {
251250
}
252251
}
253252
253+
function replaceLinksWithTag(str: string) {
254+
return str.replace(
255+
LINKABLE_URL_REGEX,
256+
(url: string) => `<a href="${url}" target="_blank" class="link">${url}</a>`,
257+
)
258+
}
259+
254260
function escapeHTML(str: string) {
255261
const mapping: Record<string, string> = {
256262
'&': '&amp;',
@@ -438,10 +444,7 @@ function toLinkField(fieldName: string, options: LinkFieldOptions = {}): ColDef
438444
params.node?.rowPinned === 'top' ?
439445
null
440446
: `Double click to view this ${tooltipValue ?? 'value'} in a separate component`,
441-
cellRenderer: (params: ICellRendererParams) =>
442-
params.node.rowPinned === 'top' ?
443-
`<div> ${params.value}</div>`
444-
: `<div class='link'> ${params.value} </div>`,
447+
cellRenderer: (params: ICellRendererParams) => `<div class='link'> ${params.value} </div>`,
445448
}
446449
}
447450

0 commit comments

Comments
 (0)