Skip to content

Commit

Permalink
Restricting 'unsafe characters' from entering into video link tooltip.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasBaskys committed May 24, 2019
1 parent 4018f0e commit becd172
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/components/tools/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,15 @@ class Editor extends React.Component<Props> {
}

checkVideoHostname = e => {
const expression = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi;
const regex = new RegExp(expression);
const urlExpression = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi;
const unsafeExpression = /[#%^"{}|<>`~\\\][]/g;
const urlRegex = new RegExp(urlExpression);
const unsafeCharsRegex = new RegExp(unsafeExpression);

if (e.target.value.match(regex)) {
if (
e.target.value.match(urlRegex) &&
!e.target.value.match(unsafeCharsRegex)
) {
e.target.parentElement.classList.remove('invalid');
} else {
e.target.parentElement.classList.add('invalid');
Expand Down

0 comments on commit becd172

Please sign in to comment.