Skip to content

Commit

Permalink
fix browser DNS resolution; closes #251
Browse files Browse the repository at this point in the history
  • Loading branch information
thatmattlove committed Jun 1, 2024
1 parent c8a348e commit c79ba8b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion hyperglass/ui/components/looking-glass-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
[],
);

Expand Down
13 changes: 5 additions & 8 deletions hyperglass/ui/util/common.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
});
5 changes: 4 additions & 1 deletion hyperglass/ui/util/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

0 comments on commit c79ba8b

Please sign in to comment.