regex-for-http

pull/1225/head
Vincent 5 years ago
parent d429390e62
commit bcad497c7f

@ -7,6 +7,8 @@ const nodeFetch = require('node-fetch');
const validOpenGroupServer = async serverUrl => {
// test to make sure it's online (and maybe has a valid SSL cert)
try {
console.log('[vince] loki_public_chat_api --> serverUrl:', serverUrl);
const url = new URL(serverUrl);
if (window.lokiFeatureFlags.useFileOnionRequests) {

@ -7,8 +7,10 @@ interface OpenGroupParams {
}
export class OpenGroup {
// Matches prefixes https:// http:// plus no prefix.
// Servers without prefix default to https://
private static readonly serverRegex = new RegExp(
'^([\\w-]{2,}.){1,2}[\\w-]{2,}$'
'^(https?:\\/\\/){0,1}([\\w-]{2,}.){1,2}[\\w-]{2,}$'
);
private static readonly groupIdRegex = new RegExp(
'^publicChat:[0-9]*@([\\w-]{2,}.){1,2}[\\w-]{2,}$'
@ -17,10 +19,22 @@ export class OpenGroup {
public readonly channel: number;
public readonly groupId?: string;
public readonly conversationId: string;
private readonly rawServer: string;
constructor(params: OpenGroupParams) {
const strippedServer = params.server.replace('https://', '');
this.server = strippedServer;
// https will be prepended unless explicitly http
const prefixRegex = new RegExp('https:\//\//');
this.rawServer = params.server.replace(prefixRegex, '');
const isHttps = Boolean(params.server.match('^(https:\/\/){1}'));
const isHttp = Boolean(params.server.match('^(http:\/\/){1}'));
const hasNoPrefix = !(params.server.match(prefixRegex));
console.log('[vince] isHttps:', isHttps);
console.log('[vince] isHttp:', isHttp);
console.log('[vince] hasNoPrefix:', hasNoPrefix);
this.server = params.server;
// Validate server format
const isValid = OpenGroup.serverRegex.test(this.server);
@ -28,6 +42,8 @@ export class OpenGroup {
throw Error('an invalid server or groupId was provided');
}
console.log('[vince] OpenGroup --> constructor:', this.server);
this.channel = params.channel;
this.conversationId = params.conversationId;
this.groupId = OpenGroup.getGroupId(this.server, this.channel);

Loading…
Cancel
Save