Skip to content

Full Toolkit for Next-Level Domain Analysis

Only treat the whole search input as an IP 🔎 (#137)

Felix Wotschofsky15f8d9d65094
diff --git a/lib/search-parser.test.ts b/lib/search-parser.test.ts
index 1681c61..b57969d 100644
--- a/lib/search-parser.test.ts
+++ b/lib/search-parser.test.ts
@@ -150,6 +150,13 @@ describe('parseSearchInput', () => {
});
});
+ it('looks up the host of a URL whose path or query contains an IP', () => {
+ expect(
+ parseSearchInput('https://www.example.com/?y=ipr:192.0.2.1:1793711503'),
+ ).toEqual({ type: 'domain', value: 'www.example.com' });
+ expect(parseSearchInput('example.com/8.8.8.8').type).not.toBe('ip');
+ });
+
it('handles wildcard domains', () => {
expect(parseSearchInput('*.example.com')).toEqual({
type: 'domain',
diff --git a/lib/search-parser.ts b/lib/search-parser.ts
index b6c74ff..5adf10b 100644
--- a/lib/search-parser.ts
+++ b/lib/search-parser.ts
@@ -1,6 +1,7 @@
import { toASCII } from 'punycode';
+import isIP from 'validator/lib/isIP';
-import { IPV4_REGEX, IPV6_REGEX, isValidDomain } from './utils';
+import { isValidDomain } from './utils';
export const normalizeDomain = (input: string): string => {
let tDomain;
@@ -30,7 +31,8 @@ export const parseSearchInput = (input: string): SearchResult => {
} as const;
}
- if (trimmedInput.match(IPV4_REGEX) || trimmedInput.match(IPV6_REGEX)) {
+ // Whole input only: the shared IP regexes find IPs inside text, such as a URL's query.
+ if (isIP(trimmedInput)) {
return {
type: 'ip',
value: trimmedInput,