mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-22 07:53:34 +01:00
fix: validate docs links (#3122)
* fix: validate docs links * fix: only allow external urls, ignore filesystem paths * fix: updates * chore: revert spacing
This commit is contained in:
parent
938e0560a2
commit
07baa63e9d
@ -2,6 +2,7 @@ import MarkdownIt from 'markdown-it';
|
|||||||
import * as MarkdownItReplaceLink from 'markdown-it-replace-link';
|
import * as MarkdownItReplaceLink from 'markdown-it-replace-link';
|
||||||
import StyledWrapper from './StyledWrapper';
|
import StyledWrapper from './StyledWrapper';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { isValidUrl } from 'utils/url/index';
|
||||||
|
|
||||||
const Markdown = ({ collectionPath, onDoubleClick, content }) => {
|
const Markdown = ({ collectionPath, onDoubleClick, content }) => {
|
||||||
const markdownItOptions = {
|
const markdownItOptions = {
|
||||||
@ -15,7 +16,7 @@ const Markdown = ({ collectionPath, onDoubleClick, content }) => {
|
|||||||
if (target.tagName === 'A') {
|
if (target.tagName === 'A') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const href = target.getAttribute('href');
|
const href = target.getAttribute('href');
|
||||||
if (href) {
|
if (href && isValidUrl(href)) {
|
||||||
window.open(href, '_blank');
|
window.open(href, '_blank');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -129,8 +129,15 @@ app.on('ready', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||||
require('electron').shell.openExternal(details.url);
|
try {
|
||||||
|
const { protocol } = new URL(url);
|
||||||
|
if (['https:', 'http:'].includes(protocol)) {
|
||||||
|
require('electron').shell.openExternal(url);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
return { action: 'deny' };
|
return { action: 'deny' };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user