fix: optimize regexp creation

This commit is contained in:
Yarmo Mackenbach 2024-01-23 20:02:02 +01:00
parent a9c1ffabfe
commit 7639962521
No known key found for this signature in database
GPG key ID: C248C28D432560ED
2 changed files with 6 additions and 5 deletions

View file

@ -20,6 +20,8 @@ import { parseProfileJws } from '../asp.js'
export const timeout = 5000 export const timeout = 5000
const reURI = /^aspe:([a-zA-Z0-9.\-_]*):([a-zA-Z0-9]*)/
/** /**
* Execute a fetch request * Execute a fetch request
* @function * @function
@ -39,7 +41,6 @@ export async function fn (data, opts) {
}) })
const fetchPromise = new Promise((resolve, reject) => { const fetchPromise = new Promise((resolve, reject) => {
const reURI = /^aspe:([a-zA-Z0-9.\-_]*):([a-zA-Z0-9]*)/
const match = data.aspeUri.match(reURI) const match = data.aspeUri.match(reURI)
if (!data.aspeUri || !reURI.test(data.aspeUri) || !isFQDN(match[1])) { if (!data.aspeUri || !reURI.test(data.aspeUri) || !isFQDN(match[1])) {

View file

@ -18,15 +18,15 @@ import { ServiceProvider } from '../serviceProvider.js'
export const reURI = /^(.*)/ export const reURI = /^(.*)/
const reURIHkp = /^openpgp4fpr:(?:0x)?([a-zA-Z0-9.\-_]*)/
const reURIWkdDirect = /^https:\/\/(.*)\/.well-known\/openpgpkey\/hu\/([a-zA-Z0-9]*)(?:\?l=(.*))?/
const reURIWkdAdvanced = /^https:\/\/(openpgpkey.*)\/.well-known\/openpgpkey\/(.*)\/hu\/([a-zA-Z0-9]*)(?:\?l=(.*))?/
/** /**
* @function * @function
* @param {string} uri * @param {string} uri
*/ */
export function processURI (uri) { export function processURI (uri) {
const reURIHkp = /^openpgp4fpr:(?:0x)?([a-zA-Z0-9.\-_]*)/
const reURIWkdDirect = /^https:\/\/(.*)\/.well-known\/openpgpkey\/hu\/([a-zA-Z0-9]*)(?:\?l=(.*))?/
const reURIWkdAdvanced = /^https:\/\/(openpgpkey.*)\/.well-known\/openpgpkey\/(.*)\/hu\/([a-zA-Z0-9]*)(?:\?l=(.*))?/
let reURI = null let reURI = null
let mode = null let mode = null
let match = null let match = null