Skip to content

Commit

Permalink
check if is url
Browse files Browse the repository at this point in the history
  • Loading branch information
Sartxi committed Jul 16, 2024
1 parent b07ae91 commit eb0a6ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libs/blocks/locui/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '../utils/miloc.js';
import { signal } from '../../../deps/htm-preact.js';
import Modal from './modal.js';
import isUrl from '../utils/url.js';

export const showRolloutOptions = signal(false);

Expand Down Expand Up @@ -67,7 +68,10 @@ function findMetaFragments(doc) {
const metas = doc.getElementsByTagName('meta');
if (metas.length) {
fragments = [...metas]
.filter((meta) => meta.getAttribute('content')?.includes('/fragments/'))
.filter((meta) => {
const content = meta.getAttribute('content');
return content?.includes('/fragments/') && isUrl(content);
})
.map((meta) => new URL(meta.getAttribute('content')));
}
return fragments;
Expand Down
8 changes: 8 additions & 0 deletions libs/blocks/locui/utils/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function isUrl(str) {
try {
const url = new URL(str);
return url;
} catch (error) {
return false;
}
}

0 comments on commit eb0a6ae

Please sign in to comment.