Skip to content

Commit 168b1a2

Browse files
authored
[CLNP-6478] tel and mailto to markdown URL protocol (#1320)
Fixes [CLNP-6478](https://sendbird.atlassian.net/browse/CLNP-6478) ### Changelogs - Added `tel` and `mailto` to supported markdown URL protocols ### Checklist Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If unsure, ask the members. This is a reminder of what we look for before merging your code. - [x] **All tests pass locally with my changes** - [x] **I have added tests that prove my fix is effective or that my feature works** - [ ] **Public components / utils / props are appropriately exported** - [ ] I have added necessary documentation (if appropriate) [CLNP-6478]: https://sendbird.atlassian.net/browse/CLNP-6478?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent a29f8aa commit 168b1a2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/modules/Message/utils/tokens/__tests__/asSafeUrl.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ describe('asSafeURL', () => {
44
test('should return the same URL if it is already safe', () => {
55
expect(asSafeURL('http://example.com')).toBe('http://example.com');
66
expect(asSafeURL('https://example.com')).toBe('https://example.com');
7+
expect(asSafeURL('mailto:[email protected]')).toBe('mailto:[email protected]');
8+
expect(asSafeURL('tel:+14081234567')).toBe('tel:+14081234567');
79
});
810

911
test('should return a safe URL if it is not safe', () => {
10-
expect(asSafeURL('mailto:[email protected]')).toBe('#');
1112
// eslint-disable-next-line no-script-url
1213
expect(asSafeURL('javascript:alert(1)')).toBe('#');
1314
expect(asSafeURL('javascript%3Aalert%281%29')).toBe('#');
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
const supportedProtocols = ['https:', 'http:', 'tel:', 'mailto:'];
2+
13
export function asSafeURL(url: string) {
24
let safeURL = decodeURIComponent(url);
3-
45
try {
56
const { protocol } = new URL(safeURL);
6-
if (['https:', 'http:'].some((it) => it === protocol.toLowerCase())) {
7+
if (supportedProtocols.some((it) => it === protocol.toLowerCase())) {
78
return safeURL;
89
} else {
910
return '#';
@@ -13,6 +14,5 @@ export function asSafeURL(url: string) {
1314
safeURL = 'https://' + safeURL;
1415
}
1516
}
16-
1717
return safeURL;
1818
}

0 commit comments

Comments
 (0)