Skip to content

Fix for bugs relating to ntpath.expanduser() #40279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
josiahcarlson mannequin opened this issue May 20, 2004 · 16 comments
Closed

Fix for bugs relating to ntpath.expanduser() #40279

josiahcarlson mannequin opened this issue May 20, 2004 · 16 comments

Comments

@josiahcarlson
Copy link
Mannequin

josiahcarlson mannequin commented May 20, 2004

BPO 957650
Nosy @mwhudson, @loewis, @birkenfeld, @josiahcarlson, @tiran
Files
  • ntpath.patch: Patch for ntpath that fixes bugs.
  • ntpath_test.txt: Testing output on unpatched and patched ntpath
  • ntpath_updated.patch: Updated patch for expanduser and expandvars
  • ntpath_full.patch: expanduser, expandvars, doc, and tests
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-10-15.06:15:08.249>
    created_at = <Date 2004-05-20.20:35:05.000>
    labels = ['OS-windows']
    title = 'Fix for bugs relating to ntpath.expanduser()'
    updated_at = <Date 2009-04-30.14:56:22.337>
    user = 'https://github.com/josiahcarlson'

    bugs.python.org fields:

    activity = <Date 2009-04-30.14:56:22.337>
    actor = 'gjb1002'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-10-15.06:15:08.249>
    closer = 'loewis'
    components = ['Windows']
    creation = <Date 2004-05-20.20:35:05.000>
    creator = 'josiahcarlson'
    dependencies = []
    files = ['5983', '5984', '5985', '5986']
    hgrepos = []
    issue_num = 957650
    keywords = ['patch']
    message_count = 16.0
    messages = ['46031', '46032', '46033', '46034', '46035', '46036', '46037', '46038', '46039', '46040', '46041', '46042', '74158', '74191', '86842', '86843']
    nosy_count = 7.0
    nosy_names = ['mwh', 'loewis', 'georg.brandl', 'josiahcarlson', 'gjb1002', 'chomo', 'christian.heimes']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue957650'
    versions = ['Python 2.6', 'Python 3.0']

    @josiahcarlson
    Copy link
    Mannequin Author

    josiahcarlson mannequin commented May 20, 2004

    Attached is a patch for sf bug bpo-796219 that fixes
    ntpath.expanduser() for paths that embed other
    environment variables, and also includes functionality
    that mirrors *nix-style ~user\extra expansions.

    I will comment with output from both the unpatched and
    patched version of ntpath.

    @josiahcarlson josiahcarlson mannequin closed this as completed May 20, 2004
    @josiahcarlson josiahcarlson mannequin closed this as completed May 20, 2004
    @josiahcarlson
    Copy link
    Mannequin Author

    josiahcarlson mannequin commented May 20, 2004

    Logged In: YES
    user_id=341410

    #test setup:
    >>> import os
    >>> os.environ['TESTING'] = '%TESTING1%'
    >>> os.environ['TESTING1'] = '%TESTING2%'
    >>> os.environ['TESTING2'] = 'Final\\Path'
    
    #test standard ntpath
    >>> import ntpath
    >>> ntpath.expanduser('~')
    'C:\\Documents and Settings\\jcarlson'
    >>> ntpath.expanduser('~billy')
    '~billy'
    >>> ntpath.expanduser('~billy\\bob')
    '~billy\\bob'
    >>> ntpath.expanduser('~\\bob')
    'C:\\Documents and Settings\\jcarlson\\bob'
    >>>
    ntpath.expanduser('~billy\\%TESTING%\\%TESTING1%\\%TESTING2%')
    '~billy\\%TESTING%\\%TESTING1%\\%TESTING2%'
    
    #test patched ntpath
    >>> import ntpath_patched
    >>> ntpath_patched.expanduser('~')
    'C:Documents and Settings\\jcarlson'
    >>> ntpath_patched.expanduser('~billy')
    'C:Documents and Settings\\billy'
    >>> ntpath_patched.expanduser('~billy\\bob')
    'C:Documents and Settings\\billy\\bob'
    >>> ntpath_patched.expanduser('~\\bob')
    'C:Documents and Settings\\jcarlson\\bob'
    >>>
    ntpath_patched.expanduser('~billy\\%TESTING%\\%TESTING1%\\%TESTING2%')
    'C:Documents and
    Settings\\billy\\Final\\Path\\Final\\Path\\Final\\Path'

    @josiahcarlson
    Copy link
    Mannequin Author

    josiahcarlson mannequin commented May 20, 2004

    Logged In: YES
    user_id=341410

    I uploaded the testing as text to alleviate text wrapping
    issues that could confuse.

    @chomo
    Copy link
    Mannequin

    chomo mannequin commented Jun 14, 2004

    Logged In: YES
    user_id=943591

    this problem maybe is whats
    needed

    @josiahcarlson
    Copy link
    Mannequin Author

    josiahcarlson mannequin commented Jun 15, 2004

    Logged In: YES
    user_id=341410

    What problem is needed?

    Perhaps you mean "this solution is desireable".

    @mwhudson
    Copy link

    Logged In: YES
    user_id=6656

    This looks much better to me!

    @mwhudson
    Copy link

    Logged In: YES
    user_id=6656

    bugger, wrong report :-/

    @josiahcarlson
    Copy link
    Mannequin Author

    josiahcarlson mannequin commented Oct 22, 2006

    Logged In: YES
    user_id=341410

    I've just attached an updated version of the patch to handle
    expandusers (without recursive environment variable
    expansion), as well as a variant of
    http://python.org/sf/1574252 to handle %VAR% style
    expansions on Windows.

    @birkenfeld
    Copy link
    Member

    The patch looks good to me; documentation updates and new tests will be needed though.

    @birkenfeld
    Copy link
    Member

    This fixes bpo-796219.

    @josiahcarlson
    Copy link
    Mannequin Author

    josiahcarlson mannequin commented Mar 13, 2007

    I have just attached an updated patch (against trunk) for ntpath expandusers and expandvars that includes documentation and test updates.
    File Added: ntpath_full.patch

    @birkenfeld
    Copy link
    Member

    Thanks! Committed as rev. 54364.

    @tiran
    Copy link
    Member

    tiran commented Oct 2, 2008

    I just saw this bug entry in the whatsnew list. The os.path.expanduser()
    function handles ~user the wrong way. The (naive) implementation expects
    that all user directories are inside a common base path. This is only
    true for standalone Windows computers.

    There is no way to get the path to a user's home directory w/o her
    login+password or the login of a domain admin. The feature should be
    removed in 2.6.1.

    Martin, do you concur?

    @tiran tiran reopened this Oct 2, 2008
    @tiran tiran assigned loewis and unassigned birkenfeld Oct 2, 2008
    @tiran tiran reopened this Oct 2, 2008
    @tiran tiran assigned loewis and unassigned birkenfeld Oct 2, 2008
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 2, 2008

    Martin, do you concur?

    Not really. On my system, which is part of a domain, expanduser("~")
    gives 'C:\\Documents and Settings\\martin.vonloewis', which is
    indeed the directory where my profile lives. HOMEDRIVE is Y:,
    and HOMESHARE is some system in our network, but those aren't
    considered for determining ~ - although I do think
    %HOMEDRIVE%\%HOMEPATH% might have been a better choice.
    However, given the choice that was made, I think the assumption
    is correct that somebody else's profile will live in the same
    folder. Is it possible to configure a domain profile so that it's
    not in Documents and Settings?

    Even if this doesn't work for all systems, I don't think we can
    revert it for 2.6.1 (as it does give the correct answer at least
    in some cases). Such a change will have to wait for 2.7.

    @loewis loewis mannequin closed this as completed Oct 15, 2008
    @loewis loewis mannequin removed their assignment Oct 15, 2008
    @loewis loewis mannequin closed this as completed Oct 15, 2008
    @loewis loewis mannequin removed their assignment Oct 15, 2008
    @gjb1002
    Copy link
    Mannequin

    gjb1002 mannequin commented Apr 30, 2009

    Just ran into this myself, and would agree with Christian's comments. On
    my system, my home directory is a mounted network drive, hence "H:\". It
    was a bit of a surprise when os.path.expanduser("~fred") returned
    "H:\\fred"...

    This seems broken to me. It's surely better to have reliable functions
    that either work or return the path unchanged, than ones that guess and
    are wrong some of the time. At least in the above case it should be
    possible to add a special case.

    Will this be considered for Python 2.7 now? I'd suggest opening a new
    bug or reopening this one if so.

    @gjb1002
    Copy link
    Mannequin

    gjb1002 mannequin commented Apr 30, 2009

    In fact, wouldn't a very simple fix be to not return paths that don't
    exist? That would probably catch 90% of the cases.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants