From 9131b5eb2fb878cfc5234bf0a040bb5eba6cad2b Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Thu, 14 May 2020 23:35:14 +0200 Subject: [PATCH] Add another fragment test case which caused jenkins error --- scm-ui/ui-components/src/MarkdownLinkRenderer.test.tsx | 1 + scm-ui/ui-components/src/MarkdownLinkRenderer.tsx | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/scm-ui/ui-components/src/MarkdownLinkRenderer.test.tsx b/scm-ui/ui-components/src/MarkdownLinkRenderer.test.tsx index a9cc02ddfe..7390ee0709 100644 --- a/scm-ui/ui-components/src/MarkdownLinkRenderer.test.tsx +++ b/scm-ui/ui-components/src/MarkdownLinkRenderer.test.tsx @@ -30,6 +30,7 @@ const pathname = basePath + "README.md/"; describe("correctLocalLink tests", () => { it("should return same url", () => { expect(correctLocalLink(pathname, "")).toBe(pathname); + expect(correctLocalLink(pathname, "#42")).toBe("#42"); }); it("should return main directory", () => { diff --git a/scm-ui/ui-components/src/MarkdownLinkRenderer.tsx b/scm-ui/ui-components/src/MarkdownLinkRenderer.tsx index 4c9b9ae6ab..1c4c26020d 100644 --- a/scm-ui/ui-components/src/MarkdownLinkRenderer.tsx +++ b/scm-ui/ui-components/src/MarkdownLinkRenderer.tsx @@ -30,10 +30,6 @@ type Props = RouteComponentProps & { href: string; }; -function flatten(text: string, child: any): any { - return typeof child === "string" ? text + child : React.Children.toArray(child.props.children).reduce(flatten, text); -} - /** * Handle local SCM-Manager and external links * @@ -46,7 +42,7 @@ export function correctLocalLink(pathname: string, link: string) { // Leave uris unchanged which start with schemes const regex = new RegExp(".:"); - if (link.match(regex)) { + if (link.match(regex) || link.startsWith("#")) { return link; } @@ -79,9 +75,7 @@ export function correctLocalLink(pathname: string, link: string) { } function MarkdownLinkRenderer(props: Props) { const compositeUrl = withContextPath(correctLocalLink(props.location.pathname, props.href)); - const linkText = React.Children.toArray(props.children).reduce(flatten, ""); - - return {linkText}; + return {props.children}; } export default withRouter(MarkdownLinkRenderer);