Skip to content

Commit

Permalink
patch: fix circular dependency issue with ts util files
Browse files Browse the repository at this point in the history
  • Loading branch information
thamudi committed Nov 27, 2024
1 parent 807e9b1 commit 1721b22
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
7 changes: 4 additions & 3 deletions server/api/upload-comment.post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { predictCommentsResults } from '../utils'
import { predictCommentsResults } from '../utils/nuha-api-request'
import { reject } from '../utils/promise-handlers'

export default defineEventHandler(async (event) => {
const data = await readBody<SingleComment>(event)
Expand Down Expand Up @@ -33,14 +34,14 @@ async function verifyData(input: SingleComment): Promise<void> {
}

const emailPattern = new RegExp(

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings containing many repetitions of '\\u0001'.
/(?:[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+(?:\.[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?\.)+[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?|\[(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?|[a-zA-Z\d-]*[a-zA-Z\d]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])/gm,
/(?:[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+(?:\.[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?\.)+[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?|\[(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?|[a-zA-Z\d-]*[a-zA-Z\d]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])/gm
)
if (input.comment.match(emailPattern)) {
return reject('apiResponse.commentContainsEmail')
}

const urlPattern = new RegExp(
/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gm,
/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gm
)
if (input.comment.match(urlPattern)) {
return reject('apiResponse.commentContainsUrl')
Expand Down
4 changes: 2 additions & 2 deletions server/api/upload-file.post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileParser, getFileParser, getFileType } from '../utils'
import { FileParser, getFileParser, getFileType } from '../utils/file-parser'

export default defineEventHandler(async (event) => {
const files = await readMultipartFormData(event)
Expand All @@ -8,7 +8,7 @@ export default defineEventHandler(async (event) => {
}

const fileType = getFileType(
files[0].filename?.substring(files[0].filename?.lastIndexOf('.') + 1) ?? '',
files[0].filename?.substring(files[0].filename?.lastIndexOf('.') + 1) ?? ''
)
let err: unknown
const parser = await getFileParser(fileType).catch((_err) => {
Expand Down
1 change: 1 addition & 0 deletions server/utils/file-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parse } from 'csv-parse/sync'
import { resolve, reject } from './promise-handlers'
import xlsx from 'node-xlsx'

export interface FileParser {
Expand Down
12 changes: 0 additions & 12 deletions server/utils/index.ts

This file was deleted.

0 comments on commit 1721b22

Please sign in to comment.