PCRE2 standard applied

This commit is contained in:
DomySh
2022-07-01 02:29:28 +02:00
parent 8d41b94c36
commit 509fdbc8ca
14 changed files with 66 additions and 155 deletions

View File

@@ -74,5 +74,6 @@ export type RegexAddForm = {
regex:string,
is_case_sensitive:boolean,
is_blacklist:boolean,
mode:string // C->S S->C BOTH
mode:string, // C->S S->C BOTH,
active: boolean
}

View File

@@ -152,50 +152,7 @@ export async function serviceregexlist(service_id:string){
return await getapi(`service/${service_id}/regexes`) as RegexFilter[];
}
const unescapedChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~ ";
export function getHumanReadableRegex(regexB64:string){
const regex = Buffer.from(regexB64, "base64")
let res = ""
for (let i=0; i < regex.length; i++){
const byte = String.fromCharCode(regex[i]);
if (unescapedChars.includes(byte)){
res+=byte
}else{
let hex_data = regex[i].toString(16)
if (hex_data.length === 1) hex_data = "0"+hex_data
res+="%"+hex_data
}
}
return res
}
const hexChars = "0123456789abcdefABCDEF"
export function getBinaryRegex(regexPercentageEncoded:string):number[]{
const regex = Buffer.from(regexPercentageEncoded)
let res = []
for (let i=0; i < regex.length; i++){
const byte = String.fromCharCode(regex[i]);
if ("%" === byte){
if(i+2 < regex.length){
const byte_1 = String.fromCharCode(regex[i+1]);
const byte_2 = String.fromCharCode(regex[i+2]);
if(hexChars.includes(byte_1) && hexChars.includes(byte_2)){
res.push(parseInt(byte_1+byte_2,16))
i += 2
}else{
res.push(regex[i])
}
}else{
res.push(regex[i])
}
}else{
res.push(regex[i])
}
}
return res
}
export function errorNotify(title:string, description:string ){
showNotification({
@@ -220,3 +177,7 @@ export function okNotify(title:string, description:string ){
export function b64encode(data:number[]|string){
return Buffer.from(data).toString('base64')
}
export function b64decode(regexB64:string){
return Buffer.from(regexB64, "base64").toString()
}