Skip to content

Commit a637344

Browse files
Fallback to previous, more approximative hashtag RE on older browsers (#14513)
Fixes #14511
1 parent 63bbe6c commit a637344

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

app/javascript/mastodon/features/compose/containers/warning_container.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@ import PropTypes from 'prop-types';
55
import { FormattedMessage } from 'react-intl';
66
import { me } from '../../../initial_state';
77

8-
const HASHTAG_SEPARATORS = "_\\u00b7\\u200c";
9-
const ALPHA = '\\p{L}\\p{M}';
10-
const WORD = '\\p{L}\\p{M}\\p{N}\\p{Pc}';
11-
const APPROX_HASHTAG_RE = new RegExp(
12-
'(?:^|[^\\/\\)\\w])#((' +
13-
'[' + WORD + '_]' +
14-
'[' + WORD + HASHTAG_SEPARATORS + ']*' +
15-
'[' + ALPHA + HASHTAG_SEPARATORS + ']' +
16-
'[' + WORD + HASHTAG_SEPARATORS +']*' +
17-
'[' + WORD + '_]' +
18-
')|(' +
19-
'[' + WORD + '_]*' +
20-
'[' + ALPHA + ']' +
21-
'[' + WORD + '_]*' +
22-
'))', 'iu'
23-
);
8+
const buildHashtagRE = () => {
9+
try {
10+
const HASHTAG_SEPARATORS = "_\\u00b7\\u200c";
11+
const ALPHA = '\\p{L}\\p{M}';
12+
const WORD = '\\p{L}\\p{M}\\p{N}\\p{Pc}';
13+
return new RegExp(
14+
'(?:^|[^\\/\\)\\w])#((' +
15+
'[' + WORD + '_]' +
16+
'[' + WORD + HASHTAG_SEPARATORS + ']*' +
17+
'[' + ALPHA + HASHTAG_SEPARATORS + ']' +
18+
'[' + WORD + HASHTAG_SEPARATORS +']*' +
19+
'[' + WORD + '_]' +
20+
')|(' +
21+
'[' + WORD + '_]*' +
22+
'[' + ALPHA + ']' +
23+
'[' + WORD + '_]*' +
24+
'))', 'iu'
25+
);
26+
} catch {
27+
return /(?:^|[^\/\)\w])#(\w*[a-zA-Z·]\w*)/i;
28+
}
29+
};
30+
31+
const APPROX_HASHTAG_RE = buildHashtagRE();
2432

2533
const mapStateToProps = state => ({
2634
needsLockWarning: state.getIn(['compose', 'privacy']) === 'private' && !state.getIn(['accounts', me, 'locked']),

0 commit comments

Comments
 (0)