Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: alert detail markdown link bug #3683

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions web/src/app/util/safeURL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,13 @@ describe('safeURL', () => {
'[0987654321](tel:1234567890)',
],
})

checkIt('should work with query params', {
true: [
'[https://example.com/query?foo=1&bar=2](https://example.com/query?foo=1&bar=2)',
],
false: [
'[https://example.com/query?foo=1&bar=2](https://example.com/query?foo=1&bar=2]',
],
})
})
15 changes: 15 additions & 0 deletions web/src/app/util/safeURL.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
// encodeHtmlEntities will encode common HTML entities in a string.
//
// This is useful for ensuring that comparisons between html encoded urls and
// non-encoded labels are accurate
function encodeHtmlEntities(text: string): string {
return text
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
}

// safeURL will determine if a url is safe for linking.
//
// It tries to determine if the label is misleading.
export function safeURL(url: string, label: string): boolean {
label = encodeHtmlEntities(label)

if (url.startsWith('mailto:')) {
const email = url.substr(7)
return email === label && email.includes('@')
Expand Down
Loading