~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/interpret.py

  • Committer: David Coles
  • Date: 2010-07-17 11:32:50 UTC
  • Revision ID: coles.david@gmail.com-20100717113250-vi18n50bcjmfmzrt
Show warning for CGI header field-names which contain restricted characters.

Forbidden characters are the separators defined by RFC3875. This is mainly to 
fix an issue where printing a dictionary (with no CGI headers) could be 
assumed to be a CGI header with no warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
286
286
        process_cgi_output(req, line + '\n', cgiflags)
287
287
        return
288
288
 
 
289
    # Check if CGI field-name is valid
 
290
    CGI_SEPERATORS = set(['(', ')', '<', '>', '@', ',', ';', ':', '\\', '"',
 
291
            '/', '[', ']', '?', '=', '{', '}', ' ', '\t'])
 
292
    if any((char in CGI_SEPERATORS for char in name)):
 
293
        warning = "Warning"
 
294
        if not cgiflags.gentle:
 
295
            message = """An unexpected server error has occured."""
 
296
            warning = "Error"
 
297
        else:
 
298
            # Header contained illegal characters
 
299
            message = """You printed an invalid CGI header. CGI header
 
300
            field-names can not contain any of the following characters: 
 
301
            <code>( ) &lt; &gt; @ , ; : \\ " / [ ] ? = { } <em>SPACE 
 
302
            TAB</em></code>."""
 
303
        write_html_warning(req, message, warning=warning)
 
304
        cgiflags.wrote_html_warning = True
 
305
        # Handle the rest of this line as normal data
 
306
        process_cgi_output(req, line + '\n', cgiflags)
 
307
        return
 
308
 
289
309
    # Read CGI headers
290
310
    value = value.strip()
291
311
    if name == "Content-Type":