From 4eeede75098d62e505dc1e36c9ffaa179e4825e9 Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard27 Date: Mon, 5 Dec 2022 17:17:55 +0100 Subject: [PATCH 01/11] feat: restructured logic for internal links --- .../app/src/components/cms/rich-content.tsx | 14 +++---- .../app/src/components/content-teaser.tsx | 38 +++---------------- packages/app/src/components/markdown.tsx | 24 +++++------- .../components/page-links.tsx | 24 ++++-------- .../utils/__tests__/is-absolute-url.spec.ts | 17 --------- .../utils/__tests__/is-internal-url.spec.ts | 22 +++++++++++ packages/app/src/utils/is-absolute-url.ts | 6 --- packages/app/src/utils/is-internal-url.ts | 9 +++++ 8 files changed, 60 insertions(+), 94 deletions(-) delete mode 100644 packages/app/src/utils/__tests__/is-absolute-url.spec.ts create mode 100644 packages/app/src/utils/__tests__/is-internal-url.spec.ts delete mode 100644 packages/app/src/utils/is-absolute-url.ts create mode 100644 packages/app/src/utils/is-internal-url.ts diff --git a/packages/app/src/components/cms/rich-content.tsx b/packages/app/src/components/cms/rich-content.tsx index 736ed39545..27055ff1e3 100644 --- a/packages/app/src/components/cms/rich-content.tsx +++ b/packages/app/src/components/cms/rich-content.tsx @@ -22,7 +22,7 @@ import { nestedHtml } from '~/style/preset'; import { asResponsiveArray } from '~/style/utils'; import { ImageBlock, InlineAttachment, InlineCollapsibleList, InlineLink, RichContentImageBlock } from '~/types/cms'; import { assert } from '~/utils/assert'; -import { isAbsoluteUrl } from '~/utils/is-absolute-url'; +import { isInternalUrl } from '~/utils/is-internal-url'; import { Link } from '~/utils/link'; import { AccessibilityDefinition } from '~/utils/use-accessibility-annotations'; import { Heading } from '../typography'; @@ -251,17 +251,17 @@ function InlineLinkMark(props: { children: ReactNode; mark: InlineLink }) { if (!mark.href) return <>{children}; - return isAbsoluteUrl(mark.href) ? ( - - {children} - - - ) : ( + return isInternalUrl(mark.href) ? ( {children} + ) : ( + + {children} + + ); } diff --git a/packages/app/src/components/content-teaser.tsx b/packages/app/src/components/content-teaser.tsx index 42310f0d5f..6b0eef1c63 100644 --- a/packages/app/src/components/content-teaser.tsx +++ b/packages/app/src/components/content-teaser.tsx @@ -6,7 +6,7 @@ import { PublicationDate } from '~/components/publication-date'; import { Text } from '~/components/typography'; import { SiteText } from '~/locale'; import { ImageBlock } from '~/types/cms'; -import { isAbsoluteUrl } from '~/utils/is-absolute-url'; +import { isInternalUrl } from '~/utils/is-internal-url'; import { useBreakpoints } from '~/utils/use-breakpoints'; export interface ContentTeaserProps { @@ -21,34 +21,14 @@ export interface ContentTeaserProps { text: SiteText['pages']['topical_page']['shared']; } -export function ContentTeaser({ - title, - slug, - cover, - category, - publicationDate, - variant = 'normal', - isWeeklyHighlight, - isArticle, - text, -}: ContentTeaserProps) { +export function ContentTeaser({ title, slug, cover, category, publicationDate, variant = 'normal', isWeeklyHighlight, isArticle, text }: ContentTeaserProps) { const breakpoints = useBreakpoints(true); const imageWidth = variant === 'normal' ? (breakpoints.sm ? 186 : 90) : 90; return ( - + - + @@ -62,15 +42,7 @@ export function ContentTeaser({ )} } iconPlacement="right" underline diff --git a/packages/app/src/components/markdown.tsx b/packages/app/src/components/markdown.tsx index 88b8e8fd08..4df0ee6658 100644 --- a/packages/app/src/components/markdown.tsx +++ b/packages/app/src/components/markdown.tsx @@ -5,15 +5,12 @@ import styled from 'styled-components'; import { ExternalLink } from '~/components/external-link'; import { useIntl } from '~/intl'; import { nestedHtml } from '~/style/preset'; -import { isAbsoluteUrl } from '~/utils/is-absolute-url'; +import { isInternalUrl } from '~/utils/is-internal-url'; import { Link } from '~/utils/link'; import { DisplayOnMatchingQueryCode } from './display-on-matching-query-code'; import { Message } from './message'; import { Anchor } from './typography'; -import { - ChevronRight, - External as ExternalLinkIcon, -} from '@corona-dashboard/icons'; +import { ChevronRight, External as ExternalLinkIcon } from '@corona-dashboard/icons'; interface MarkdownProps { content: string; @@ -26,17 +23,17 @@ interface LinkProps { const renderers = { link: (props: LinkProps) => - isAbsoluteUrl(props.href) ? ( - - {props.children} - - - ) : ( + isInternalUrl(props.href) ? ( {props.children} + ) : ( + + {props.children} + + ), /** * The code element is hijacked to display context-aware pieces of content. @@ -67,10 +64,7 @@ const renderers = { const hasChildBlockquote = props.node.children[0].type === 'blockquote'; return ( - + {props.children} ); diff --git a/packages/app/src/components/page-information-block/components/page-links.tsx b/packages/app/src/components/page-information-block/components/page-links.tsx index b3be6f39f6..b39d8c4198 100644 --- a/packages/app/src/components/page-information-block/components/page-links.tsx +++ b/packages/app/src/components/page-information-block/components/page-links.tsx @@ -1,7 +1,4 @@ -import { - ChevronRight, - External as ExternalIcon, -} from '@corona-dashboard/icons'; +import { ChevronRight, External as ExternalIcon } from '@corona-dashboard/icons'; import css from '@styled-system/css'; import styled from 'styled-components'; import { Box } from '~/components/base'; @@ -11,7 +8,7 @@ import { useIntl } from '~/intl'; import { spacingStyle } from '~/style/functions/spacing'; import { space } from '~/style/theme'; import { asResponsiveArray } from '~/style/utils'; -import { isAbsoluteUrl } from '~/utils/is-absolute-url'; +import { isInternalUrl } from '~/utils/is-internal-url'; import { Link } from '~/utils/link'; interface pageLinksProps { @@ -24,8 +21,7 @@ interface pageLinksProps { export function PageLinks({ links }: pageLinksProps) { const { commonTexts } = useIntl(); - const combinedAriaLabel = (title: string) => - `${commonTexts.informatie_header.external_link}. ${title}`; + const combinedAriaLabel = (title: string) => `${commonTexts.informatie_header.external_link}. ${title}`; return ( @@ -33,20 +29,16 @@ export function PageLinks({ links }: pageLinksProps) { {links.map((link, index) => ( - {isAbsoluteUrl(link.href) ? ( - - } /> - - ) : ( + {isInternalUrl(link.href) ? ( } /> + ) : ( + + } /> + )} ))} diff --git a/packages/app/src/utils/__tests__/is-absolute-url.spec.ts b/packages/app/src/utils/__tests__/is-absolute-url.spec.ts deleted file mode 100644 index d96b6fbe7a..0000000000 --- a/packages/app/src/utils/__tests__/is-absolute-url.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { suite } from 'uvu'; -import * as assert from 'uvu/assert'; -import { isAbsoluteUrl } from '../is-absolute-url'; - -const IsAbsoluteUrl = suite('isAbsoluteUrl'); - -IsAbsoluteUrl('returns true for absolute urls', () => { - const url = 'https://www.rijksoverheid.nl'; - assert.ok(isAbsoluteUrl(url)); -}); - -IsAbsoluteUrl('returns false for relative urls', () => { - const url = '/vaccinaties'; - assert.not.ok(isAbsoluteUrl(url)); -}); - -IsAbsoluteUrl.run(); diff --git a/packages/app/src/utils/__tests__/is-internal-url.spec.ts b/packages/app/src/utils/__tests__/is-internal-url.spec.ts new file mode 100644 index 0000000000..09aa6d55d1 --- /dev/null +++ b/packages/app/src/utils/__tests__/is-internal-url.spec.ts @@ -0,0 +1,22 @@ +import { suite } from 'uvu'; +import * as assert from 'uvu/assert'; +import { isInternalUrl } from '../is-internal-url'; + +const IsInternalUrl = suite('isInternalUrl'); + +IsInternalUrl('returns false for external absolute urls', () => { + const url = 'https://www.rijksoverheid.nl'; + assert.not.ok(isInternalUrl(url)); +}); + +IsInternalUrl('returns true for relative urls', () => { + const url = '/vaccinaties'; + assert.ok(isInternalUrl(url)); +}); + +IsInternalUrl('returns true for Corona Dashboard absolute urls', () => { + const url = 'https://coronadashboard.rijksoverheid.nl/landelijk/vaccinaties'; + assert.ok(isInternalUrl(url)); +}); + +IsInternalUrl.run(); diff --git a/packages/app/src/utils/is-absolute-url.ts b/packages/app/src/utils/is-absolute-url.ts deleted file mode 100644 index aa47bc07b5..0000000000 --- a/packages/app/src/utils/is-absolute-url.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Return true if the given url starts with http or https - */ -export function isAbsoluteUrl(url: string) { - return /^(https?:)?\/\//.test(url); -} diff --git a/packages/app/src/utils/is-internal-url.ts b/packages/app/src/utils/is-internal-url.ts new file mode 100644 index 0000000000..8c07c58467 --- /dev/null +++ b/packages/app/src/utils/is-internal-url.ts @@ -0,0 +1,9 @@ +/** + * Return true if the given url starts with http or https + */ +export function isInternalUrl(url: string) { + const regExExternal = new RegExp('(https?://coronadashboard.)'); + const regExInternal = new RegExp('^(https?:)?//'); + + return regExExternal.test(url) || !regExInternal.test(url); +} From 777c78552d737989f07275cfe6e4ac1965f186d6 Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard27 Date: Thu, 8 Dec 2022 09:04:35 +0100 Subject: [PATCH 02/11] fix: resolved conversations --- .../app/src/utils/__tests__/is-internal-url.spec.ts | 4 ++++ packages/app/src/utils/is-internal-url.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/app/src/utils/__tests__/is-internal-url.spec.ts b/packages/app/src/utils/__tests__/is-internal-url.spec.ts index 09aa6d55d1..28ba0b581c 100644 --- a/packages/app/src/utils/__tests__/is-internal-url.spec.ts +++ b/packages/app/src/utils/__tests__/is-internal-url.spec.ts @@ -19,4 +19,8 @@ IsInternalUrl('returns true for Corona Dashboard absolute urls', () => { assert.ok(isInternalUrl(url)); }); +IsInternalUrl('returns true for Corona Dashboard anchor links', () => { + const href = '#'; + assert.ok(isInternalUrl(href)); +}); IsInternalUrl.run(); diff --git a/packages/app/src/utils/is-internal-url.ts b/packages/app/src/utils/is-internal-url.ts index 8c07c58467..1ff6434479 100644 --- a/packages/app/src/utils/is-internal-url.ts +++ b/packages/app/src/utils/is-internal-url.ts @@ -1,9 +1,11 @@ /** - * Return true if the given url starts with http or https + * Return true if the given url starts with http://coronadashboard. or https://coronadashboard. + * Return false if the given url starts with http or https */ -export function isInternalUrl(url: string) { - const regExExternal = new RegExp('(https?://coronadashboard.)'); +export function isInternalUrl(url: string, href: string) { + const regExAnchor = new RegExp('(#)'); + const regExExternal = new RegExp('^(https?://coronadashboard.)'); const regExInternal = new RegExp('^(https?:)?//'); - return regExExternal.test(url) || !regExInternal.test(url); + return (regExAnchor.test(href) && regExExternal.test(url)) || !regExInternal.test(url); } From 249866a32c1c91bd1d1479a577261bfd20bb7f7c Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard27 Date: Thu, 8 Dec 2022 09:14:52 +0100 Subject: [PATCH 03/11] fix: fixed faild test part --- packages/app/src/utils/is-internal-url.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/utils/is-internal-url.ts b/packages/app/src/utils/is-internal-url.ts index 1ff6434479..98f6d725bf 100644 --- a/packages/app/src/utils/is-internal-url.ts +++ b/packages/app/src/utils/is-internal-url.ts @@ -7,5 +7,5 @@ export function isInternalUrl(url: string, href: string) { const regExExternal = new RegExp('^(https?://coronadashboard.)'); const regExInternal = new RegExp('^(https?:)?//'); - return (regExAnchor.test(href) && regExExternal.test(url)) || !regExInternal.test(url); + return regExAnchor.test(href) || regExExternal.test(url) || !regExInternal.test(url); } From 4f242a76f5a6bd3ab4b828921279fc1177d66ffa Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard27 Date: Thu, 8 Dec 2022 09:47:45 +0100 Subject: [PATCH 04/11] fix: fixed faild test part --- packages/app/src/utils/__tests__/is-internal-url.spec.ts | 4 ++-- packages/app/src/utils/is-internal-url.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/app/src/utils/__tests__/is-internal-url.spec.ts b/packages/app/src/utils/__tests__/is-internal-url.spec.ts index 28ba0b581c..cbddc5d098 100644 --- a/packages/app/src/utils/__tests__/is-internal-url.spec.ts +++ b/packages/app/src/utils/__tests__/is-internal-url.spec.ts @@ -20,7 +20,7 @@ IsInternalUrl('returns true for Corona Dashboard absolute urls', () => { }); IsInternalUrl('returns true for Corona Dashboard anchor links', () => { - const href = '#'; - assert.ok(isInternalUrl(href)); + const url = '#'; + assert.ok(isInternalUrl(url)); }); IsInternalUrl.run(); diff --git a/packages/app/src/utils/is-internal-url.ts b/packages/app/src/utils/is-internal-url.ts index 98f6d725bf..ed9e4b0ec8 100644 --- a/packages/app/src/utils/is-internal-url.ts +++ b/packages/app/src/utils/is-internal-url.ts @@ -2,10 +2,10 @@ * Return true if the given url starts with http://coronadashboard. or https://coronadashboard. * Return false if the given url starts with http or https */ -export function isInternalUrl(url: string, href: string) { - const regExAnchor = new RegExp('(#)'); - const regExExternal = new RegExp('^(https?://coronadashboard.)'); +export function isInternalUrl(url: string) { + const regExAnchor = new RegExp('^(#)'); + const regExExternal = new RegExp('^(https?://coronadashboard)'); const regExInternal = new RegExp('^(https?:)?//'); - return regExAnchor.test(href) || regExExternal.test(url) || !regExInternal.test(url); + return regExAnchor.test(url) || regExExternal.test(url) || !regExInternal.test(url); } From a93729960e29491079b8aab3b381b216a8e708de Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard18 <93984341+VWSCoronaDashboard18@users.noreply.github.com> Date: Mon, 12 Dec 2022 16:07:33 +0100 Subject: [PATCH 05/11] pr feedback: updating the regex and test files --- .../utils/__tests__/is-internal-url.spec.ts | 65 ++++++++++++++----- packages/app/src/utils/is-internal-url.ts | 8 ++- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/packages/app/src/utils/__tests__/is-internal-url.spec.ts b/packages/app/src/utils/__tests__/is-internal-url.spec.ts index cbddc5d098..0ae8aea928 100644 --- a/packages/app/src/utils/__tests__/is-internal-url.spec.ts +++ b/packages/app/src/utils/__tests__/is-internal-url.spec.ts @@ -2,25 +2,60 @@ import { suite } from 'uvu'; import * as assert from 'uvu/assert'; import { isInternalUrl } from '../is-internal-url'; -const IsInternalUrl = suite('isInternalUrl'); +const externalLinks = [ + '', + '23498', + '//random-text', + 'with spaces included', + 'www.google. com', + 'http://www.google.com', + 'https://www.google.com', + 'coronadashboard.rivm.nl', + 'http://coronadashboard.rivm.nl', + 'https://coronadashboard.rivm.nl', + 'news-paper.nl/new-coronadashboard-is-live', + 'http://news-paper.nl/new-coronadashboard-is-live', + 'https://news-paper.nl/new-coronadashboard-is-live', + 'www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="coronadashboard.rijksoverheid.nl"', + 'www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="http://coronadashboard.rijksoverheid.nl"', + 'www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="https://coronadashboard.rijksoverheid.nl"', + 'http://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="coronadashboard.riiksoverheid.nl"', + 'http://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="http://coronadashboard.rijksoverheid.nl"', + 'http://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="https://coronadashboard.rijksoverheid.nl"', + 'https://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="coronadashboard.rijksoverheid.nl"', + 'https://www.riiksoverheid.nl/see-our-new-dahsboard/?tracking="http://coronadashboard.rijksoverheid.nl"', + 'https://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="https://coronadashboard.rijksoverheid.nl"', +]; -IsInternalUrl('returns false for external absolute urls', () => { - const url = 'https://www.rijksoverheid.nl'; - assert.not.ok(isInternalUrl(url)); -}); +const internalLinksCommon = ['#anchor', '/']; -IsInternalUrl('returns true for relative urls', () => { - const url = '/vaccinaties'; - assert.ok(isInternalUrl(url)); -}); +const interalLinksProd = [ + 'coronadashboard.nl', + 'http://coronadashboard.nl', + 'https://coronadashboard.nl', + 'www.coronadashboard.nl', + 'http://www.coronadashboard.nl', + 'https://www.coronadashboard.nl', + 'coronadashboard.rijskoverheid.nl', + 'http://coronadashboard.rijskoverheid.nl', + 'https://coronadashboard.rijskoverheid.nl', + 'coronadashboard.government.nl', + 'http://coronadashboard.government.nl', + 'https://coronadashboard.government.nl', +]; -IsInternalUrl('returns true for Corona Dashboard absolute urls', () => { - const url = 'https://coronadashboard.rijksoverheid.nl/landelijk/vaccinaties'; - assert.ok(isInternalUrl(url)); +const IsInternalUrl = suite('isInternalUrl'); + +IsInternalUrl('returns false for external urls', () => { + externalLinks.forEach((url) => { + assert.not.ok(isInternalUrl(url), `${url} is seen as an internal link but probbably is an external url`); + }); }); -IsInternalUrl('returns true for Corona Dashboard anchor links', () => { - const url = '#'; - assert.ok(isInternalUrl(url)); +IsInternalUrl('returns true for internal urls', () => { + [...internalLinksCommon, ...interalLinksProd].forEach((url) => { + assert.ok(isInternalUrl(url), `${url} is seen as an external link but probbably is an internal url`); + }); }); + IsInternalUrl.run(); diff --git a/packages/app/src/utils/is-internal-url.ts b/packages/app/src/utils/is-internal-url.ts index ed9e4b0ec8..2f725b045b 100644 --- a/packages/app/src/utils/is-internal-url.ts +++ b/packages/app/src/utils/is-internal-url.ts @@ -4,8 +4,10 @@ */ export function isInternalUrl(url: string) { const regExAnchor = new RegExp('^(#)'); - const regExExternal = new RegExp('^(https?://coronadashboard)'); - const regExInternal = new RegExp('^(https?:)?//'); + const regExInternal = new RegExp('^(/)[^/]'); + const regExInternalBaseDomain = new RegExp('^((https?://)?coronadashboard.rijskoverheid.nl)'); + const regExInternalEnglishDomain = new RegExp('^((https?://)?coronadashboard.government.nl)'); + const regExInternalShortDomain = new RegExp('^(((https?://(www.)?)?|www.)coronadashboard.nl)'); - return regExAnchor.test(url) || regExExternal.test(url) || !regExInternal.test(url); + return regExAnchor.test(url) || regExInternal.test(url) || regExInternalBaseDomain.test(url) || regExInternalEnglishDomain.test(url) || regExInternalShortDomain.test(url); } From 12d369bb15c6f498e111945ef4041d0effb92298 Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard18 <93984341+VWSCoronaDashboard18@users.noreply.github.com> Date: Mon, 12 Dec 2022 21:33:31 +0100 Subject: [PATCH 06/11] Update regex not being fully sufficient. --- packages/app/src/utils/is-internal-url.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/utils/is-internal-url.ts b/packages/app/src/utils/is-internal-url.ts index 2f725b045b..e0d6b5b5ab 100644 --- a/packages/app/src/utils/is-internal-url.ts +++ b/packages/app/src/utils/is-internal-url.ts @@ -4,7 +4,7 @@ */ export function isInternalUrl(url: string) { const regExAnchor = new RegExp('^(#)'); - const regExInternal = new RegExp('^(/)[^/]'); + const regExInternal = new RegExp('^(/)[^/]|^(/)$'); const regExInternalBaseDomain = new RegExp('^((https?://)?coronadashboard.rijskoverheid.nl)'); const regExInternalEnglishDomain = new RegExp('^((https?://)?coronadashboard.government.nl)'); const regExInternalShortDomain = new RegExp('^(((https?://(www.)?)?|www.)coronadashboard.nl)'); From 50f497a7c8a4249de867dd57a39a21f6a1151c8a Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard18 <93984341+VWSCoronaDashboard18@users.noreply.github.com> Date: Mon, 12 Dec 2022 21:39:03 +0100 Subject: [PATCH 07/11] Combine all regexes in to one regex --- packages/app/src/utils/is-internal-url.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/app/src/utils/is-internal-url.ts b/packages/app/src/utils/is-internal-url.ts index e0d6b5b5ab..f120fecb96 100644 --- a/packages/app/src/utils/is-internal-url.ts +++ b/packages/app/src/utils/is-internal-url.ts @@ -3,11 +3,7 @@ * Return false if the given url starts with http or https */ export function isInternalUrl(url: string) { - const regExAnchor = new RegExp('^(#)'); - const regExInternal = new RegExp('^(/)[^/]|^(/)$'); - const regExInternalBaseDomain = new RegExp('^((https?://)?coronadashboard.rijskoverheid.nl)'); - const regExInternalEnglishDomain = new RegExp('^((https?://)?coronadashboard.government.nl)'); - const regExInternalShortDomain = new RegExp('^(((https?://(www.)?)?|www.)coronadashboard.nl)'); + const totalRegEx = new RegExp('(^(#))|(^(/)[^/]|^(/)$)|(^(((https?://(www.)?)?|www.)coronadashboard(.rijskoverheid|.government)?.nl))'); - return regExAnchor.test(url) || regExInternal.test(url) || regExInternalBaseDomain.test(url) || regExInternalEnglishDomain.test(url) || regExInternalShortDomain.test(url); + return totalRegEx.test(url); } From ef17c77fa769a2ff32bbe91719cda068963dc95f Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard18 <93984341+VWSCoronaDashboard18@users.noreply.github.com> Date: Mon, 12 Dec 2022 21:41:19 +0100 Subject: [PATCH 08/11] update description comment --- packages/app/src/utils/is-internal-url.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/app/src/utils/is-internal-url.ts b/packages/app/src/utils/is-internal-url.ts index f120fecb96..6825522715 100644 --- a/packages/app/src/utils/is-internal-url.ts +++ b/packages/app/src/utils/is-internal-url.ts @@ -1,7 +1,9 @@ /** - * Return true if the given url starts with http://coronadashboard. or https://coronadashboard. - * Return false if the given url starts with http or https + * Return true if the given url is an internal link to one of the dashboard pages. + * This counts for international links as well. + * Return false if the given link is an external link. */ + export function isInternalUrl(url: string) { const totalRegEx = new RegExp('(^(#))|(^(/)[^/]|^(/)$)|(^(((https?://(www.)?)?|www.)coronadashboard(.rijskoverheid|.government)?.nl))'); From fb69c0eae9ce510a5260946d045da4432de275b4 Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard18 <93984341+VWSCoronaDashboard18@users.noreply.github.com> Date: Thu, 15 Dec 2022 15:23:13 +0100 Subject: [PATCH 09/11] Fix typos --- .../components/page-links.tsx | 2 +- .../utils/__tests__/is-internal-url.spec.ts | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/app/src/components/page-information-block/components/page-links.tsx b/packages/app/src/components/page-information-block/components/page-links.tsx index b39d8c4198..6466fefa8c 100644 --- a/packages/app/src/components/page-information-block/components/page-links.tsx +++ b/packages/app/src/components/page-information-block/components/page-links.tsx @@ -24,7 +24,7 @@ export function PageLinks({ links }: pageLinksProps) { const combinedAriaLabel = (title: string) => `${commonTexts.informatie_header.external_link}. ${title}`; return ( - + {commonTexts.informatie_header.handige_links} {links.map((link, index) => ( diff --git a/packages/app/src/utils/__tests__/is-internal-url.spec.ts b/packages/app/src/utils/__tests__/is-internal-url.spec.ts index 0ae8aea928..e506bc1e92 100644 --- a/packages/app/src/utils/__tests__/is-internal-url.spec.ts +++ b/packages/app/src/utils/__tests__/is-internal-url.spec.ts @@ -16,15 +16,15 @@ const externalLinks = [ 'news-paper.nl/new-coronadashboard-is-live', 'http://news-paper.nl/new-coronadashboard-is-live', 'https://news-paper.nl/new-coronadashboard-is-live', - 'www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="coronadashboard.rijksoverheid.nl"', - 'www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="http://coronadashboard.rijksoverheid.nl"', - 'www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="https://coronadashboard.rijksoverheid.nl"', - 'http://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="coronadashboard.riiksoverheid.nl"', - 'http://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="http://coronadashboard.rijksoverheid.nl"', - 'http://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="https://coronadashboard.rijksoverheid.nl"', - 'https://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="coronadashboard.rijksoverheid.nl"', - 'https://www.riiksoverheid.nl/see-our-new-dahsboard/?tracking="http://coronadashboard.rijksoverheid.nl"', - 'https://www.rijksoverheid.nl/see-our-new-dahsboard/?tracking="https://coronadashboard.rijksoverheid.nl"', + 'www.rijksoverheid.nl/see-our-new-dashboard/?tracking="coronadashboard.rijksoverheid.nl"', + 'www.rijksoverheid.nl/see-our-new-dashboard/?tracking="http://coronadashboard.rijksoverheid.nl"', + 'www.rijksoverheid.nl/see-our-new-dashboard/?tracking="https://coronadashboard.rijksoverheid.nl"', + 'http://www.rijksoverheid.nl/see-our-new-dashboard/?tracking="coronadashboard.riiksoverheid.nl"', + 'http://www.rijksoverheid.nl/see-our-new-dashboard/?tracking="http://coronadashboard.rijksoverheid.nl"', + 'http://www.rijksoverheid.nl/see-our-new-dashboard/?tracking="https://coronadashboard.rijksoverheid.nl"', + 'https://www.rijksoverheid.nl/see-our-new-dashboard/?tracking="coronadashboard.rijksoverheid.nl"', + 'https://www.riiksoverheid.nl/see-our-new-dashboard/?tracking="http://coronadashboard.rijksoverheid.nl"', + 'https://www.rijksoverheid.nl/see-our-new-dashboard/?tracking="https://coronadashboard.rijksoverheid.nl"', ]; const internalLinksCommon = ['#anchor', '/']; @@ -36,9 +36,9 @@ const interalLinksProd = [ 'www.coronadashboard.nl', 'http://www.coronadashboard.nl', 'https://www.coronadashboard.nl', - 'coronadashboard.rijskoverheid.nl', - 'http://coronadashboard.rijskoverheid.nl', - 'https://coronadashboard.rijskoverheid.nl', + 'coronadashboard.rijksoverheid.nl', + 'http://coronadashboard.rijksoverheid.nl', + 'https://coronadashboard.rijksoverheid.nl', 'coronadashboard.government.nl', 'http://coronadashboard.government.nl', 'https://coronadashboard.government.nl', @@ -48,13 +48,13 @@ const IsInternalUrl = suite('isInternalUrl'); IsInternalUrl('returns false for external urls', () => { externalLinks.forEach((url) => { - assert.not.ok(isInternalUrl(url), `${url} is seen as an internal link but probbably is an external url`); + assert.not.ok(isInternalUrl(url), `${url} is seen as an internal link but probably is an external url`); }); }); IsInternalUrl('returns true for internal urls', () => { [...internalLinksCommon, ...interalLinksProd].forEach((url) => { - assert.ok(isInternalUrl(url), `${url} is seen as an external link but probbably is an internal url`); + assert.ok(isInternalUrl(url), `${url} is seen as an external link but probably is an internal url`); }); }); From 3b91eac8ea88cda3abd2729cb8c71e1a124ef6ba Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard18 <93984341+VWSCoronaDashboard18@users.noreply.github.com> Date: Thu, 15 Dec 2022 15:28:38 +0100 Subject: [PATCH 10/11] Write pt as paddingTop --- .../components/page-information-block/components/page-links.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/components/page-information-block/components/page-links.tsx b/packages/app/src/components/page-information-block/components/page-links.tsx index 6466fefa8c..88940ad522 100644 --- a/packages/app/src/components/page-information-block/components/page-links.tsx +++ b/packages/app/src/components/page-information-block/components/page-links.tsx @@ -24,7 +24,7 @@ export function PageLinks({ links }: pageLinksProps) { const combinedAriaLabel = (title: string) => `${commonTexts.informatie_header.external_link}. ${title}`; return ( - + {commonTexts.informatie_header.handige_links} {links.map((link, index) => ( From bd26bb612c9beaff7aba38100deb688507c797a9 Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard18 <93984341+VWSCoronaDashboard18@users.noreply.github.com> Date: Thu, 15 Dec 2022 15:56:00 +0100 Subject: [PATCH 11/11] Fix typo in other file as well --- packages/app/src/utils/is-internal-url.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/utils/is-internal-url.ts b/packages/app/src/utils/is-internal-url.ts index 6825522715..bf88dea57e 100644 --- a/packages/app/src/utils/is-internal-url.ts +++ b/packages/app/src/utils/is-internal-url.ts @@ -5,7 +5,7 @@ */ export function isInternalUrl(url: string) { - const totalRegEx = new RegExp('(^(#))|(^(/)[^/]|^(/)$)|(^(((https?://(www.)?)?|www.)coronadashboard(.rijskoverheid|.government)?.nl))'); + const totalRegEx = new RegExp('(^(#))|(^(/)[^/]|^(/)$)|(^(((https?://(www.)?)?|www.)coronadashboard(.rijksoverheid|.government)?.nl))'); return totalRegEx.test(url); }