Skip to content

Commit f64cd79

Browse files
committed
fix: fix ip string isn't pure
1 parent 97708a9 commit f64cd79

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/pages/Requests/components/RequestModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
TabsTrigger,
2626
} from '@/components/ui/tabs'
2727
import { RequestItem } from '@/types'
28-
import { isFalsy, isTruthy } from '@/utils'
28+
import { isFalsy, isTruthy, onlyIP } from '@/utils'
2929
import fetcher from '@/utils/fetcher'
3030

3131
import MethodBadge from './MethodBadge'
@@ -153,7 +153,7 @@ const RequestModal: React.FC<RequestModalProps> = ({ req, ...props }) => {
153153
<div>{t('requests.remote_ip')}</div>
154154
<div>
155155
<a
156-
href={`https://ip.sb/ip/${req.remoteAddress}`}
156+
href={`https://ip.sb/ip/${onlyIP(req.remoteAddress)}`}
157157
target="_blank"
158158
rel="noreferrer noopener"
159159
>

src/pages/Scripting/Evaluate/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { lazy, Suspense, useCallback, useState } from 'react'
22
import { toast } from 'react-hot-toast'
33
import { useTranslation } from 'react-i18next'
4-
import { css } from '@emotion/react'
54
import { LifeBuoy } from 'lucide-react'
65

76
import CodeContent from '@/components/CodeContent'

src/utils/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ export const forceRefresh = async (): Promise<void> => {
1616

1717
window.location.reload()
1818
}
19+
20+
/**
21+
* The following IP formats can be handled:
22+
* 1.1.1.1(Proxy),
23+
* 1.1.1.1 (Proxy),
24+
* 2001:0db8:85a3:0000:0000:8a2e:0370:7334(Proxy),
25+
* 2001:0db8:85a3:0000:0000:8a2e:0370:7334 (Proxy),
26+
*/
27+
export const onlyIP = (ip: string) => {
28+
const ipAddressRegex =
29+
/(?:\d{1,3}\.){3}\d{1,3}|(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}/g
30+
const matchArray = ip.match(ipAddressRegex)
31+
return matchArray?.length ? matchArray[0] : ip
32+
}

0 commit comments

Comments
 (0)