mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 15:33:11 +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 StyledWrapper from './StyledWrapper';
|
||||
import React from 'react';
|
||||
import { isValidUrl } from 'utils/url/index';
|
||||
|
||||
const Markdown = ({ collectionPath, onDoubleClick, content }) => {
|
||||
const markdownItOptions = {
|
||||
@ -15,7 +16,7 @@ const Markdown = ({ collectionPath, onDoubleClick, content }) => {
|
||||
if (target.tagName === 'A') {
|
||||
event.preventDefault();
|
||||
const href = target.getAttribute('href');
|
||||
if (href) {
|
||||
if (href && isValidUrl(href)) {
|
||||
window.open(href, '_blank');
|
||||
return;
|
||||
}
|
||||
|
@ -129,8 +129,15 @@ app.on('ready', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
require('electron').shell.openExternal(details.url);
|
||||
mainWindow.webContents.setWindowOpenHandler(({ 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' };
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user