Add isURL helper; fix getURL helper (#14086)

pull/14089/head
Douglas Gubert 7 years ago committed by Rodrigo Nascimento
parent f8bde388ea
commit 10d3c84a13
  1. 3
      app/custom-oauth/client/custom_oauth_client.js
  2. 5
      app/custom-oauth/server/custom_oauth_server.js
  3. 3
      app/oembed/server/server.js
  4. 5
      app/ui/client/views/app/room.js
  5. 5
      app/utils/lib/getURL.js
  6. 1
      app/utils/lib/isURL.js

@ -5,6 +5,7 @@ import { Random } from 'meteor/random';
import { ServiceConfiguration } from 'meteor/service-configuration';
import { OAuth } from 'meteor/oauth';
import s from 'underscore.string';
import { isURL } from '../../utils/lib/isURL';
// Request custom OAuth credentials for the user
// @param options {optional}
@ -47,7 +48,7 @@ export class CustomOAuth {
this.authorizePath = options.authorizePath;
this.scope = options.scope;
if (!/^https?:\/\/.+/.test(this.authorizePath)) {
if (!isURL(this.authorizePath)) {
this.authorizePath = this.serverURL + this.authorizePath;
}
}

@ -7,6 +7,7 @@ import { ServiceConfiguration } from 'meteor/service-configuration';
import { Logger } from '../../logger';
import { Users } from '../../models';
import _ from 'underscore';
import { isURL } from '../../utils/lib/isURL';
const logger = new Logger('CustomOAuth');
@ -70,11 +71,11 @@ export class CustomOAuth {
this.identityTokenSentVia = this.tokenSentVia;
}
if (!/^https?:\/\/.+/.test(this.tokenPath)) {
if (!isURL(this.tokenPath)) {
this.tokenPath = this.serverURL + this.tokenPath;
}
if (!/^https?:\/\/.+/.test(this.identityPath)) {
if (!isURL(this.identityPath)) {
this.identityPath = this.serverURL + this.identityPath;
}

@ -11,6 +11,7 @@ import iconv from 'iconv-lite';
import ipRangeCheck from 'ip-range-check';
import he from 'he';
import jschardet from 'jschardet';
import { isURL } from '../../utils/lib/isURL';
const request = HTTPInternals.NpmModules.request.module;
const OEmbed = {};
@ -254,7 +255,7 @@ OEmbed.rocketUrlParser = function(message) {
if (item.ignoreParse === true) {
return;
}
if (!/^https?:\/\//i.test(item.url)) {
if (!isURL(item.url)) {
return;
}
const data = OEmbed.getUrlMetaWithCache(item.url);

@ -32,6 +32,7 @@ import Clipboard from 'clipboard';
import { lazyloadtick } from '../../../../lazy-load';
import { ChatMessages } from '../../lib/chatMessages';
import { fileUpload } from '../../lib/fileUpload';
import { isURL } from '../../../../utils/lib/isURL';
export const chatMessages = {};
@ -561,7 +562,7 @@ Template.room.events({
return;
}
if (e.target && (e.target.nodeName === 'A') && /^https?:\/\/.+/.test(e.target.getAttribute('href'))) {
if (e.target && (e.target.nodeName === 'A') && isURL(e.target.getAttribute('href'))) {
e.preventDefault();
e.stopPropagation();
}
@ -590,7 +591,7 @@ Template.room.events({
return;
}
if (e.target && (e.target.nodeName === 'A') && /^https?:\/\/.+/.test(e.target.getAttribute('href'))) {
if (e.target && (e.target.nodeName === 'A') && isURL(e.target.getAttribute('href'))) {
if (touchMoved === true) {
e.preventDefault();
e.stopPropagation();

@ -1,8 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { settings } from '../../settings';
import s from 'underscore.string';
import { isURL } from './isURL';
export const getURL = (path, { cdn = true, full = false } = {}) => {
if (isURL(path)) {
return path;
}
const cdnPrefix = s.rtrim(s.trim(settings.get('CDN_PREFIX') || ''), '/');
const pathPrefix = s.rtrim(s.trim(__meteor_runtime_config__.ROOT_URL_PATH_PREFIX || ''), '/');

@ -0,0 +1 @@
export const isURL = (str) => /^https?:\/\//.test(str);
Loading…
Cancel
Save