Skip to content

Commit

Permalink
Support link highlighting on capitalized link scheme (mattermost#6056)
Browse files Browse the repository at this point in the history
* Support link highlighting on capitalized link scheme

* Add unit tests for urlFilter function
  • Loading branch information
CeesJol authored Mar 16, 2022
1 parent 3f73514 commit 23f3fb1
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/components/markdown/markdown.js
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ export default class Markdown extends PureComponent {
urlFilter = (url) => {
const scheme = getScheme(url);

return !scheme || this.props.autolinkedUrlSchemes.indexOf(scheme) !== -1;
return !scheme || this.props.autolinkedUrlSchemes.indexOf(scheme.toLowerCase()) !== -1;
};

createRenderer = () => {
31 changes: 30 additions & 1 deletion app/components/markdown/markdown.test.js
Original file line number Diff line number Diff line change
@@ -4,11 +4,13 @@
import {shallow} from 'enzyme';
import React from 'react';

import {General} from '../../mm-redux/constants';

import Markdown from './markdown.js';

describe('Markdown', () => {
const baseProps = {
autolinkedUrlSchemes: ['mattermost'],
autolinkedUrlSchemes: General.DEFAULT_AUTOLINKED_URL_SCHEMES,
baseTextStyle: {},
mentionKeys: [{key: 'user.name'}, {key: '@channel'}, {key: '@all'}, {key: '@here'}],
minimumHashtagLength: 3,
@@ -56,4 +58,31 @@ describe('Markdown', () => {
<Markdown {...props}/>,
);
});

test('should return true for an uncapitalized scheme', () => {
const url = 'https://www.mattermost.com/';
const wrapper = shallow(
<Markdown {...baseProps}/>,
);

expect(wrapper.instance().urlFilter(url)).toBe(true);
});

test('should return true for a capitalized scheme', () => {
const url = 'Https://www.mattermost.com/';
const wrapper = shallow(
<Markdown {...baseProps}/>,
);

expect(wrapper.instance().urlFilter(url)).toBe(true);
});

test('should return false for an unknown scheme', () => {
const url = 'unknown://www.mattermost.com/';
const wrapper = shallow(
<Markdown {...baseProps}/>,
);

expect(wrapper.instance().urlFilter(url)).toBe(false);
});
});

0 comments on commit 23f3fb1

Please sign in to comment.