forked from mirrors/thatmattlove-hyperglass
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(
|
const isFqdnQuery = useCallback(
|
||||||
(target: string | string[], fieldType: Directive['fieldType'] | null): boolean =>
|
(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 { describe, expect, it, test } from 'vitest';
|
||||||
import { all, chunkArray, entries, dedupObjectArray, andJoin, isFQDN } from './common';
|
import { all, andJoin, chunkArray, dedupObjectArray, entries, isFQDN } from './common';
|
||||||
|
|
||||||
test('all - all items are truthy', () => {
|
test('all - all items are truthy', () => {
|
||||||
// biome-ignore lint/suspicious/noSelfCompare: because this is a test, duh
|
// 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', () => {
|
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", () => {
|
it("isn't an FQDN and should be false", () => {
|
||||||
expect(isFQDN('example')).toBe(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', () => {
|
it('is a longer FQDN and should be true', () => {
|
||||||
expect(isFQDN('one.two.three.four.five.example.com')).toBe(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.
|
* @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.
|
* Don't set the global flag on this.
|
||||||
* @see https://stackoverflow.com/questions/24084926/javascript-regexp-cant-use-twice
|
* @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(
|
const pattern = new RegExp(
|
||||||
/^(?!:\/\/)([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-][a-zA-Z0-9-]+\.[a-zA-Z-]{2,6}?$/im,
|
/^(?!:\/\/)([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);
|
return typeof value === 'string' && pattern.test(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue