Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/components/tooltip/Marker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,10 @@ class MarkerTooltipContents extends React.PureComponent<Props> {
}
}

// This regexp is used to test for URLs and remove their scheme for display.
const URL_SCHEME_REGEXP = /^http(s?):\/\//;
// Matches a value that is *entirely* a single http(s) URL. We only render a
// clickable link when the whole string is a URL, so a longer descriptive
// string is never turned into a broken link.
const URL_REGEXP = /^(https?:\/\/)\S+$/;

/**
* This function may return structured markup for some types suchs as table,
Expand Down Expand Up @@ -689,7 +691,8 @@ export function renderMarkerFieldValue(
</ul>
);
case 'url': {
if (!URL_SCHEME_REGEXP.test(value)) {
const match = URL_REGEXP.exec(value);
if (!match) {
return value;
}
return (
Expand All @@ -699,7 +702,7 @@ export function renderMarkerFieldValue(
rel="noreferrer"
className="marker-link-value"
>
{value.replace(URL_SCHEME_REGEXP, '')}
{value.slice(match[1].length)}
</a>
);
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/unit/__snapshots__/marker-schema.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@ Array [
</a>,
"http://example.com",
],
Array [
"url",
"https://example.com/path?query=1",
<a
className="marker-link-value"
href="https://example.com/path?query=1"
rel="noreferrer"
target="_blank"
>
example.com/path?query=1
</a>,
"https://example.com/path?query=1",
],
Array [
"url",
"loaded https://example.com successfully",
"loaded https://example.com successfully",
"loaded https://example.com successfully",
],
Array [
"url",
"https://example.com then some more text",
"https://example.com then some more text",
"https://example.com then some more text",
],
Array [
"file-path",
"/Users/me/gecko",
Expand Down
7 changes: 7 additions & 0 deletions src/test/unit/marker-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,13 @@ describe('marker schema formatting', function () {
it('supports complex formats', function () {
const entries: Array<[MarkerFormatType, unknown]> = [
['url', 'http://example.com'],
// A whole-string URL is linkified.
['url', 'https://example.com/path?query=1'],
// A URL embedded in a longer string is left as plain text.
['url', 'loaded https://example.com successfully'],
// A string that starts with a URL but continues with a text is left as
// plain text.
['url', 'https://example.com then some more text'],
['file-path', '/Users/me/gecko'],
['file-path', null],
['file-path', undefined],
Expand Down
Loading