Skip to content

Commit

Permalink
do not force display of 'http://' in links
Browse files Browse the repository at this point in the history
  • Loading branch information
tconte-pass committed Nov 6, 2024
1 parent bb02f6f commit a4312e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/libs/parsers/highlightLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const customFindUrlChunks = ({ textToHighlight }: FindChunksArgs): Chunk[
const normalizeURL = (partialURL: string): string => {
if (partialURL.startsWith('http://')) return partialURL
if (partialURL.startsWith('https://')) return partialURL
return `http://${partialURL}`
return `${partialURL}`
}

export const highlightLinks = (description: string): ParsedDescription => {
Expand Down
24 changes: 9 additions & 15 deletions src/libs/parsers/tests/highlightLinks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('highlightLinks', () => {
const parsedDescription = highlightLinks('perdu.com')

expect(parsedDescription).toEqual([
<ExternalLink key="external-link-0" url="http://perdu.com" />,
<ExternalLink key="external-link-0" url="perdu.com" />,
])
})

Expand All @@ -90,31 +90,31 @@ describe('highlightLinks', () => {
const parsedDescription = highlightLinks('www.penofchaos.com')

expect(parsedDescription).toEqual([
<ExternalLink key="external-link-0" url="http://www.penofchaos.com" />,
<ExternalLink key="external-link-0" url="www.penofchaos.com" />,
])
})

it('with path', () => {
const parsedDescription = highlightLinks('httpstat.us/418')

expect(parsedDescription).toEqual([
<ExternalLink key="external-link-0" url="http://httpstat.us/418" />,
<ExternalLink key="external-link-0" url="httpstat.us/418" />,
])
})

it('with query params', () => {
const parsedDescription = highlightLinks('httpstat.us/200?sleep=500')

expect(parsedDescription).toEqual([
<ExternalLink key="external-link-0" url="http://httpstat.us/200?sleep=500" />,
<ExternalLink key="external-link-0" url="httpstat.us/200?sleep=500" />,
])
})

it('with hash', () => {
const parsedDescription = highlightLinks('httpstat.us#anchor')

expect(parsedDescription).toEqual([
<ExternalLink key="external-link-0" url="http://httpstat.us#anchor" />,
<ExternalLink key="external-link-0" url="httpstat.us#anchor" />,
])
})
})
Expand All @@ -128,10 +128,7 @@ describe('highlightLinks', () => {

expect(parsedDescription).toEqual([
`${description1WithoutUrl} `,
<ExternalLink
key="external-link-1"
url="http://www.penofchaos.com/warham/donjon.htm"
/>,
<ExternalLink key="external-link-1" url="www.penofchaos.com/warham/donjon.htm" />,
])
})

Expand All @@ -149,12 +146,9 @@ describe('highlightLinks', () => {
const parsedDescription = highlightLinks(description)

expect(parsedDescription).toEqual([
<ExternalLink
key="external-link-0"
url="http://www.penofchaos.com/warham/donjon.htm"
/>,
<ExternalLink key="external-link-0" url="www.penofchaos.com/warham/donjon.htm" />,
'\n',
<ExternalLink key="external-link-2" url="http://perdu.com" />,
<ExternalLink key="external-link-2" url="perdu.com" />,
])
})
})
Expand All @@ -181,7 +175,7 @@ describe('highlightLinks', () => {
)

expect(parsedDescription).toEqual([
<ExternalLink key="external-link-0" url="http://www.penofchaos.com/warham/donjon.htm" />,
<ExternalLink key="external-link-0" url="www.penofchaos.com/warham/donjon.htm" />,
` ${description1WithoutUrl}`,
])
})
Expand Down

0 comments on commit a4312e1

Please sign in to comment.