Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/app/components/app/configuration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ const Configuration: FC = () => {
const [hasFetchedDetail, setHasFetchedDetail] = useState(false)
const isLoading = !hasFetchedDetail
const pathname = usePathname()
const matched = pathname.match(/\/app\/([^/]+)/)
const appId = (matched?.length && matched[1]) ? matched[1] : ''
const matched = /\/app\/([^/]+)/.exec(pathname)
const appId = matched?.[1] ?? ''
const [mode, setMode] = useState<AppModeEnum>(AppModeEnum.CHAT)
const [publishedConfig, setPublishedConfig] = useState<PublishConfig | null>(null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const convertTimezoneToOffsetStr = (timezone?: string) => {
return DEFAULT_OFFSET_STR
// Extract offset from name format like "-11:00 Niue Time" or "+05:30 India Time"
// Name format is always "{offset}:{minutes} {timezone name}"
const offsetMatch = tzItem.name.match(/^([+-]?\d{1,2}):(\d{2})/)
const offsetMatch = /^([+-]?\d{1,2}):(\d{2})/.exec(tzItem.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve performance and readability, consider defining this regular expression as a constant at the top of the file (e.g., const OFFSET_PATTERN = /^([+-]?\d{1,2}):(\d{2})/;). This prevents it from being recompiled on every call to this function.

if (!offsetMatch)
return DEFAULT_OFFSET_STR
// Parse hours and minutes separately
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const AnnotationReply = ({
const { t } = useTranslation()
const router = useRouter()
const pathname = usePathname()
const matched = pathname.match(/\/app\/([^/]+)/)
const appId = (matched?.length && matched[1]) ? matched[1] : ''
const matched = /\/app\/([^/]+)/.exec(pathname)
const appId = matched?.[1] ?? ''
const featuresStore = useFeaturesStore()
const annotationReply = useFeatures(s => s.features.annotationReply)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const VoiceParamConfig = ({
}: VoiceParamConfigProps) => {
const { t } = useTranslation()
const pathname = usePathname()
const matched = pathname.match(/\/app\/([^/]+)/)
const appId = (matched?.length && matched[1]) ? matched[1] : ''
const matched = /\/app\/([^/]+)/.exec(pathname)
const appId = matched?.[1] ?? ''
const text2speech = useFeatures(state => state.features.text2speech)
const featuresStore = useFeaturesStore()

Expand Down
5 changes: 3 additions & 2 deletions web/app/components/base/ga/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ export type IGAProps = {
gaType: GaType
}

const NONCE_PATTERN = /'nonce-([^']+)'/
const extractNonceFromCSP = (cspHeader: string | null): string | undefined => {
if (!cspHeader)
return undefined
const nonceMatch = cspHeader.match(/'nonce-([^']+)'/)
return nonceMatch ? nonceMatch[1] : undefined
const nonceMatch = NONCE_PATTERN.exec(cspHeader)
return nonceMatch?.[1]
}

const GA: FC<IGAProps> = ({
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/base/mermaid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const Flowchart = (props: FlowchartProps) => {
.split('\n')
.map((line) => {
// Gantt charts have specific syntax needs.
const taskMatch = line.match(/^\s*([^:]+?)\s*:\s*(.*)/)
const taskMatch = /^\s*([^:]+?)\s*:\s*(.*)/.exec(line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve performance and readability, consider defining this regular expression as a constant outside of the component. This prevents it from being recompiled on every render, which is especially important here since it's inside a map function.

if (!taskMatch)
return line // Not a task line, return as is.

Expand Down
2 changes: 1 addition & 1 deletion web/app/components/base/mermaid/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export function isMermaidCodeComplete(code: string): boolean {
const hasNoSyntaxErrors = !trimmedCode.includes('undefined')
&& !trimmedCode.includes('[object Object]')
&& trimmedCode.split('\n').every(line =>
!(line.includes('-->') && !line.match(/\S+\s*-->\s*\S+/)))
!(line.includes('-->') && !/\S+\s*-->\s*\S+/.test(line)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve performance and readability, consider defining this regular expression as a constant at the top of the file. This prevents it from being recompiled on every call to this function, which is especially important here since it's inside an every callback.


return hasValidStart && isBalanced && hasNoSyntaxErrors
}
Expand Down
5 changes: 3 additions & 2 deletions web/app/components/tools/mcp/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export type DuplicateAppModalProps = {
}

const DEFAULT_ICON = { type: 'emoji', icon: '🔗', background: '#6366F1' }
const FILE_ID_PATTERN = /files\/(.+?)\/file-preview/
const extractFileId = (url: string) => {
const match = url.match(/files\/(.+?)\/file-preview/)
return match ? match[1] : null
const match = FILE_ID_PATTERN.exec(url)
return match?.[1] ?? null
}
const getIcon = (data?: ToolWithProvider) => {
if (!data)
Expand Down
2 changes: 1 addition & 1 deletion web/utils/error-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const parsePluginErrorMessage = async (error: any): Promise<string> => {
// Try to extract nested JSON from PluginInvokeError
// Use greedy match .+ to capture the complete JSON object with nested braces
const pluginErrorPattern = /PluginInvokeError:\s*(\{.+\})/
const match = rawMessage.match(pluginErrorPattern)
const match = pluginErrorPattern.exec(rawMessage)

if (match) {
try {
Expand Down
2 changes: 1 addition & 1 deletion web/utils/urlValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function isPrivateOrLocalAddress(url: string): boolean {

// Check for private IP ranges
const ipv4Regex = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
const ipv4Match = hostname.match(ipv4Regex)
const ipv4Match = ipv4Regex.exec(hostname)
if (ipv4Match) {
const [, a, b] = ipv4Match.map(Number)
// 10.0.0.0/8
Expand Down
Loading