RegExp improvements suggested by LGTM (#17500)

pull/17544/head
Rodrigo Nascimento 6 years ago committed by GitHub
parent ef77a2120b
commit b1ec3dfaa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/autotranslate/server/autotranslate.js
  2. 2
      app/file-upload/server/lib/FileUpload.js
  3. 2
      app/file-upload/server/lib/proxy.js
  4. 2
      app/highlight-words/client/helper.js
  5. 12
      app/oembed/server/providers.js
  6. 4
      app/ui-message/client/messageBox/messageBoxAutogrow.js

@ -156,7 +156,7 @@ export class AutoTranslate {
message = Markdown.parseMessageNotEscaped(message);
// Some parsers (e. g. Marked) wrap the complete message in a <p> - this is unnecessary and should be ignored with respect to translations
const regexWrappedParagraph = new RegExp('^\s*<p>|<\/p>\s*$', 'gm');
const regexWrappedParagraph = new RegExp('^\\s*<p>|</p>\\s*$', 'gm');
message.msg = message.msg.replace(regexWrappedParagraph, '');
for (const tokenIndex in message.tokens) {

@ -318,7 +318,7 @@ export const FileUpload = {
// This file type can be pretty much anything, so it's better if we don't mess with the file extension
if (file.type !== 'application/octet-stream') {
const ext = mime.extension(file.type);
if (ext && new RegExp(`\.${ ext }$`, 'i').test(file.name) === false) {
if (ext && new RegExp(`\\.${ ext }$`, 'i').test(file.name) === false) {
file.name = `${ file.name }.${ ext }`;
}
}

@ -30,7 +30,7 @@ WebApp.connectHandlers.stack.unshift({
const path = parsedUrl.pathname.substr(UploadFS.config.storesPath.length + 1);
// Get store
const regExp = new RegExp('^\/([^\/\?]+)\/([^\/\?]+)$');
const regExp = new RegExp('^/([^/?]+)/([^/?]+)$');
const match = regExp.exec(path);
// Request is not valid

@ -16,7 +16,7 @@ const highlightTemplate = '$1<span class="highlight-text">$2</span>$3';
export const getRegexHighlight = (highlight) => new RegExp(`(^|\\b|[\\s\\n\\r\\t.,،'\\\"\\+!?:-])(${ s.escapeRegExp(highlight) })($|\\b|[\\s\\n\\r\\t.,،'\\\"\\+!?:-])(?![^<]*>|[^<>]*<\\/)`, 'gmi');
export const getRegexHighlightUrl = (highlight) => new RegExp(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)(${ s.escapeRegExp(highlight) })\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)`, 'gmi');
export const getRegexHighlightUrl = (highlight) => new RegExp(`https?:\/\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)(${ s.escapeRegExp(highlight) })\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)`, 'gmi');
export const highlightWords = (msg, highlights) => highlights.reduce((msg, { highlight, regex, urlRegex }) => {
const urlMatches = checkHighlightedWordsInUrls(msg, urlRegex);

@ -39,32 +39,32 @@ class Providers {
const providers = new Providers();
providers.registerProvider({
urls: [new RegExp('https?://soundcloud.com/\\S+')],
urls: [new RegExp('https?://soundcloud\\.com/\\S+')],
endPoint: 'https://soundcloud.com/oembed?format=json&maxheight=150',
});
providers.registerProvider({
urls: [new RegExp('https?://vimeo.com/[^/]+'), new RegExp('https?://vimeo.com/channels/[^/]+/[^/]+'), new RegExp('https://vimeo.com/groups/[^/]+/videos/[^/]+')],
urls: [new RegExp('https?://vimeo\\.com/[^/]+'), new RegExp('https?://vimeo\\.com/channels/[^/]+/[^/]+'), new RegExp('https://vimeo\\.com/groups/[^/]+/videos/[^/]+')],
endPoint: 'https://vimeo.com/api/oembed.json?maxheight=200',
});
providers.registerProvider({
urls: [new RegExp('https?://www.youtube.com/\\S+'), new RegExp('https?://youtu.be/\\S+')],
urls: [new RegExp('https?://www\\.youtube\\.com/\\S+'), new RegExp('https?://youtu\\.be/\\S+')],
endPoint: 'https://www.youtube.com/oembed?maxheight=200',
});
providers.registerProvider({
urls: [new RegExp('https?://www.rdio.com/\\S+'), new RegExp('https?://rd.io/\\S+')],
urls: [new RegExp('https?://www\\.rdio\\.com/\\S+'), new RegExp('https?://rd\\.io/\\S+')],
endPoint: 'https://www.rdio.com/api/oembed/?format=json&maxheight=150',
});
providers.registerProvider({
urls: [new RegExp('https?://www.slideshare.net/[^/]+/[^/]+')],
urls: [new RegExp('https?://www\\.slideshare\\.net/[^/]+/[^/]+')],
endPoint: 'https://www.slideshare.net/api/oembed/2?format=json&maxheight=200',
});
providers.registerProvider({
urls: [new RegExp('https?://www.dailymotion.com/video/\\S+')],
urls: [new RegExp('https?://www\\.dailymotion\\.com/video/\\S+')],
endPoint: 'https://www.dailymotion.com/services/oembed?maxheight=200',
});

@ -34,9 +34,9 @@ export const setupAutogrow = (textarea: HTMLTextAreaElement, shadow: HTMLDivElem
return true;
}
const shadowText = text.replace(/</g, '&lt;')
const shadowText = text.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/&/g, '&amp;')
.replace(/\n$/, '<br/>&nbsp;')
.replace(/\n/g, '<br/>')
.replace(/ {2,}/g, replaceWhitespaces);

Loading…
Cancel
Save