mirror of
https://github.com/thatmattlove/hyperglass.git
synced 2026-01-17 00:38:06 +00:00
fix browser DNS resolution; closes #251
This commit is contained in:
parent
c8a348ed0f
commit
c79ba8b727
3 changed files with 12 additions and 10 deletions
|
|
@ -72,7 +72,9 @@ export const LookingGlassForm = (): JSX.Element => {
|
|||
|
||||
const isFqdnQuery = useCallback(
|
||||
(target: string | string[], fieldType: Directive['fieldType'] | null): boolean =>
|
||||
typeof target === 'string' && fieldType === 'text' && isFQDN(target),
|
||||
(typeof target === 'string' || Array.isArray(target)) &&
|
||||
fieldType === 'text' &&
|
||||
isFQDN(target),
|
||||
[],
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { expect, describe, it, test } from 'vitest';
|
||||
import { all, chunkArray, entries, dedupObjectArray, andJoin, isFQDN } from './common';
|
||||
import { describe, expect, it, test } from 'vitest';
|
||||
import { all, andJoin, chunkArray, dedupObjectArray, entries, isFQDN } from './common';
|
||||
|
||||
test('all - all items are truthy', () => {
|
||||
// biome-ignore lint/suspicious/noSelfCompare: because this is a test, duh
|
||||
|
|
@ -79,12 +79,6 @@ describe('andJoin - join array of strings to sentence structure', () => {
|
|||
});
|
||||
|
||||
describe('isFQDN - determine if a string is an FQDN pattern', () => {
|
||||
it('is null and should be false', () => {
|
||||
expect(isFQDN(null)).toBe(false);
|
||||
});
|
||||
it('is undefined and should be false', () => {
|
||||
expect(isFQDN(undefined)).toBe(false);
|
||||
});
|
||||
it("isn't an FQDN and should be false", () => {
|
||||
expect(isFQDN('example')).toBe(false);
|
||||
});
|
||||
|
|
@ -100,4 +94,7 @@ describe('isFQDN - determine if a string is an FQDN pattern', () => {
|
|||
it('is a longer FQDN and should be true', () => {
|
||||
expect(isFQDN('one.two.three.four.five.example.com')).toBe(true);
|
||||
});
|
||||
it('is an array of FQDNs and should be true', () => {
|
||||
expect(isFQDN(['www.example.com'])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ export function andJoin(values: string[], options?: AndJoinOptions): string {
|
|||
*
|
||||
* @param value Input value.
|
||||
*/
|
||||
export function isFQDN(value: unknown): value is string {
|
||||
export function isFQDN(value: string | string[]): value is string {
|
||||
/**
|
||||
* Don't set the global flag on this.
|
||||
* @see https://stackoverflow.com/questions/24084926/javascript-regexp-cant-use-twice
|
||||
|
|
@ -142,5 +142,8 @@ export function isFQDN(value: unknown): value is string {
|
|||
const pattern = new RegExp(
|
||||
/^(?!:\/\/)([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-][a-zA-Z0-9-]+\.[a-zA-Z-]{2,6}?$/im,
|
||||
);
|
||||
if (Array.isArray(value)) {
|
||||
return isFQDN(value[0]);
|
||||
}
|
||||
return typeof value === 'string' && pattern.test(value);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue