Ticket #12671: trac_12671-fix-load-file-with-space-in-path.patch

File trac_12671-fix-load-file-with-space-in-path.patch, 1.9 KB (added by ppurka, 8 years ago)

Apply to devel/sage

  • sage/misc/preparser.py

    # HG changeset patch
    # User Punarbasu Purkayastha <ppurka@gmail.com>
    # Date 1331800092 -28800
    # Node ID 8602e5728c67c0c8525aa10ad3dbb64eca17f354
    # Parent  aaa5b1d74d52ab4bbd011856bf25ed6e39e22625
    fix load of files with spaces in absolute path
    
    diff --git a/sage/misc/preparser.py b/sage/misc/preparser.py
    a b  
    15901590        $ sage
    15911591        sage: load_attach_path()          # not tested
    15921592        ['.', '/path/to/my/library', '/path/to/utils']
     1593
     1594    Make sure that load handles filenames with spaces in the name or path::
     1595
     1596        sage: t = tmp_filename() + ' b.sage'; open(t,'w').write("print 2")
     1597        sage: sage.misc.preparser.load(t, globals())
     1598        2
    15931599    """
    15941600    try:
    15951601        filename = eval(filename, globals)
    15961602    except Exception:
    1597         # handle multiple input files separated by spaces, which was
    1598         # maybe a bad idea, but which we have to handle for backwards
    1599         # compatibility.
    1600         v = filename.split()
    1601         if len(v) > 1:
    1602             for file in v:
    1603                 load(file, globals, attach=attach)
    1604             return
     1603        # First check if the file exists. The filename may have spaces in
     1604        # its name, but more importantly modified_attached_files calls load
     1605        # with the absolute file path and that may contain spaces in the path
     1606        # As a side effect, this also allows file names with spaces in
     1607        # them, but currently I don't see a way to disallow this case.
     1608        if not os.path.exists(filename) and not os.path.isabs(filename):
     1609            # handle multiple input files separated by spaces, which was
     1610            # maybe a bad idea, but which we have to handle for backwards
     1611            # compatibility.
     1612            v = filename.split()
     1613            if len(v) > 1:
     1614                for file in v:
     1615                    load(file, globals, attach=attach)
     1616                return
    16051617
    16061618    filename = filename.strip()
    16071619