* Update twitter-text from 1.14 to 3.1.0 * Disable emoji parsing * Properly depend on twitter-text for url detection * Fix some URLs being wrongly detected client-side * Add test for server-side validation of non-autolinkable URLs * Fix server-side status length counting
		
			
				
	
	
		
			30 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import regexSupplant from 'twitter-text/dist/lib/regexSupplant';
 | |
| import validUrlPrecedingChars from 'twitter-text/dist/regexp/validUrlPrecedingChars';
 | |
| import validDomain from 'twitter-text/dist/regexp/validDomain';
 | |
| import validPortNumber from 'twitter-text/dist/regexp/validPortNumber';
 | |
| import validUrlPath from 'twitter-text/dist/regexp/validUrlPath';
 | |
| import validUrlQueryChars from 'twitter-text/dist/regexp/validUrlQueryChars';
 | |
| import validUrlQueryEndingChars from 'twitter-text/dist/regexp/validUrlQueryEndingChars';
 | |
| 
 | |
| // The difference with twitter-text's extractURL is that the protocol isn't
 | |
| // optional.
 | |
| 
 | |
| export const urlRegex = regexSupplant(
 | |
|   '('                                                          + // $1 URL
 | |
|     '(#{validUrlPrecedingChars})'                              + // $2
 | |
|     '(https?:\\/\\/)'                                          + // $3 Protocol
 | |
|     '(#{validDomain})'                                         + // $4 Domain(s)
 | |
|     '(?::(#{validPortNumber}))?'                               + // $5 Port number (optional)
 | |
|     '(\\/#{validUrlPath}*)?'                                   + // $6 URL Path
 | |
|     '(\\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?'  + // $7 Query String
 | |
|   ')',
 | |
|   {
 | |
|     validUrlPrecedingChars,
 | |
|     validDomain,
 | |
|     validPortNumber,
 | |
|     validUrlPath,
 | |
|     validUrlQueryChars,
 | |
|     validUrlQueryEndingChars,
 | |
|   },
 | |
|   'gi',
 | |
| );
 |