mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added the ability to detect and warn users about bidirectional Unicode characters. Fixes #7002
This commit is contained in:
@@ -26,6 +26,7 @@ import SwapCallsRoundedIcon from '@material-ui/icons/SwapCallsRounded';
|
||||
import _ from 'lodash';
|
||||
import { RegexIcon, FormatCaseIcon } from './ExternalIcon';
|
||||
import { isMac } from '../keyboard_shortcuts';
|
||||
import { checkTrojanSource } from '../utils';
|
||||
|
||||
const useStyles = makeStyles((theme)=>({
|
||||
root: {
|
||||
@@ -323,6 +324,11 @@ function calcFontSize(fontSize) {
|
||||
return '1em';
|
||||
}
|
||||
|
||||
function handlePaste(editor, e) {
|
||||
let copiedText = e.clipboardData.getData('text');
|
||||
checkTrojanSource(copiedText, true);
|
||||
}
|
||||
|
||||
/* React wrapper for CodeMirror */
|
||||
export default function CodeMirror({currEditor, name, value, options, events, readonly, disabled, className, autocomplete=false}) {
|
||||
const taRef = useRef();
|
||||
@@ -429,6 +435,7 @@ export default function CodeMirror({currEditor, name, value, options, events, re
|
||||
editor.current.on(eventName, events[eventName]);
|
||||
});
|
||||
editor.current.on('drop', handleDrop);
|
||||
editor.current.on('paste', handlePaste);
|
||||
initPreferences();
|
||||
return ()=>{
|
||||
editor.current?.toTextArea();
|
||||
|
||||
@@ -12,6 +12,7 @@ import $ from 'jquery';
|
||||
import gettext from 'sources/gettext';
|
||||
import 'wcdocker';
|
||||
import Notify from './helpers/Notifier';
|
||||
import { hasTrojanSource } from 'anti-trojan-source';
|
||||
|
||||
var wcDocker = window.wcDocker;
|
||||
|
||||
@@ -468,3 +469,14 @@ export function getBrowser() {
|
||||
version: M[1],
|
||||
};
|
||||
}
|
||||
|
||||
export function checkTrojanSource(content, isPasteEvent) {
|
||||
// Call the hasTrojanSource function of 'anti-trojan-source' package
|
||||
if (hasTrojanSource({ sourceText: content})) {
|
||||
let msg = gettext('The file opened contains bidirectional Unicode characters which could be interpreted differently than what is displayed. If this is unexpected it is recommended that you review the text in an application that can display hidden Unicode characters before proceeding.');
|
||||
if (isPasteEvent) {
|
||||
msg = gettext('The pasted text contains bidirectional Unicode characters which could be interpreted differently than what is displayed. If this is unexpected it is recommended that you review the text in an application that can display hidden Unicode characters before proceeding.');
|
||||
}
|
||||
Notify.alert(gettext('Trojan Source Warning'), msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user