mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	markdown: Handle SyntaxError in python_to_js_filter.
We swallow the error if our python_to_js_filter code is unable to parse some python regex properly. This ensures that the web app stays responsive. We would fail to show an accurate local echo for these regexes, however, the backend would act as the final authority for handling the realm pattern conversion.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							d936fcab3b
						
					
				
				
					commit
					15e29e209c
				
			@@ -277,7 +277,16 @@ function python_to_js_filter(pattern, url) {
 | 
			
		||||
    // message is rendered on the backend which has proper support
 | 
			
		||||
    // for negative lookbehind.
 | 
			
		||||
    pattern = pattern + /(?![\w])/.source;
 | 
			
		||||
    return [new RegExp(pattern, js_flags), url];
 | 
			
		||||
    var final_regex = null;
 | 
			
		||||
    try {
 | 
			
		||||
        final_regex = new RegExp(pattern, js_flags);
 | 
			
		||||
    } catch (ex) {
 | 
			
		||||
        // We have an error computing the generated regex syntax.
 | 
			
		||||
        // We'll ignore this realm filter for now, but log this
 | 
			
		||||
        // failure for debugging later.
 | 
			
		||||
        blueslip.error('python_to_js_filter: ' + ex.message);
 | 
			
		||||
    }
 | 
			
		||||
    return [final_regex, url];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.set_realm_filters = function (realm_filters) {
 | 
			
		||||
@@ -290,6 +299,10 @@ exports.set_realm_filters = function (realm_filters) {
 | 
			
		||||
        var pattern = realm_filter[0];
 | 
			
		||||
        var url = realm_filter[1];
 | 
			
		||||
        var js_filters = python_to_js_filter(pattern, url);
 | 
			
		||||
        if (!js_filters[0]) {
 | 
			
		||||
            // Skip any realm filters that could not be converted
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        realm_filter_map[js_filters[0]] = js_filters[1];
 | 
			
		||||
        realm_filter_list.push([js_filters[0], js_filters[1]]);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user