Support link highlighting on capitalized link scheme (#6056)

* Support link highlighting on capitalized link scheme

* Add unit tests for urlFilter function
This commit is contained in:
Cees Jol 2022-03-16 12:51:41 +01:00 committed by GitHub
parent 3f73514b98
commit 23f3fb10d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View file

@ -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 = () => {

View file

@ -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);
});
});