Subject: bug#33255: 27.0.50; expand-file-name: default directory expanded twice if relative

From: immerrr again <[email-masked]>
Date: Sun, 4 Nov 2018 11:54:49 +0100

I have recently tried to play with a clean .emacs.d directory by setting
HOME=clean/home/dir, but faced an error coming from deep inside
package-install. The error boils down to the fact that
`expand-file-name' for some reason doubles the `default-directory'
prefix when it is relative:

$ emacs -Q -batch --eval '(let ((default-directory "DEFAULT-DIR/"))
(print (expand-file-name "EXPANDED-DIR/")))'

"DEFAULT-DIR/DEFAULT-DIR/EXPANDED-DIR/"

Interestingly, if you run `expand-file-name' twice you end up with four
prefixes:

$ emacs -Q -batch --eval '(let ((default-directory "DEFAULT-DIR/"))
(print (expand-file-name (expand-file-name "EXPANDED-DIR/"))))'

"DEFAULT-DIR/DEFAULT-DIR/DEFAULT-DIR/DEFAULT-DIR/EXPANDED-DIR/"

I couldn't find any requirement for DEFAULT-DIRECTORY parameter or
`default-directory' variable to be absolute, so I would assume this is a
bug in expand-file-name.

In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
 of 2018-07-09 built on mmrcomp
Repository revision: 3307353e13a9226d477c9b1a39baae76584b90b9
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
System Description: Ubuntu 16.04.5 LTS

Recent messages:
Mark set
Saving file /home/immerrr/.cask/cask-cli.el...
Wrote /home/immerrr/.cask/cask-cli.el
Saving file /home/immerrr/.cask/cask-cli.el...
Wrote /home/immerrr/.cask/cask-cli.el
Saving file /home/immerrr/.cask/cask-cli.el...
Wrote /home/immerrr/.cask/cask-cli.el
Saving file /home/immerrr/.cask/cask-cli.el...
Wrote /home/immerrr/.cask/cask-cli.el
Mark set

Configured using:
 'configure --prefix=/home/immerrr/.local'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY
LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 THREADS JSON LCMS2

Important settings:
  value of $LC_TIME: en_GB.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: el

Minor modes in effect:
  magit-auto-revert-mode: t
  auto-revert-mode: t
  global-git-commit-mode: t
  async-bytecomp-package-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  diff-auto-refine-mode: t
  nameless-mode: t
  guide-key-mode: t
  whitespace-mode: t
  flycheck-mode: t
  shell-dirtrack-mode: t
  counsel-projectile-mode: t
  projectile-mode: t
  ivy-mode: t
  global-company-mode: t
  company-mode: t
  pyvenv-mode: t
  paredit-mode: t
  auto-compile-on-save-mode: t
  auto-compile-mode: t
  recentf-mode: t
  yas-global-mode: t
  yas-minor-mode: t
  save-place-mode: t
  show-paren-mode: t
  global-display-line-numbers-mode: t
  display-line-numbers-mode: t
  override-global-mode: t
  bar-cursor-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
/home/immerrr/.emacs.d/elpa/ample-regexps-20151023.300/init-tryout
hides /home/immerrr/.emacs.d/elpa/lua-mode-20180104.626/init-tryout

Features:
(shadow sort mail-extr emacsbug sendmail macrostep-c cmacexp macrostep
cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine
cc-vars cc-defs ielm tar-mode git-rebase rect bug-reference py-isort
executable vc vc-dispatcher magit-bookmark magit-obsolete magit-blame
magit-stash magit-bisect magit-remote magit-commit magit-sequence
magit-notes magit-worktree magit-branch magit-collab ghub url-auth
magit-files magit-refs magit-status magit dired-x magit-repos
magit-apply magit-wip magit-log magit-diff smerge-mode magit-core
magit-autorevert autorevert filenotify magit-process magit-margin
magit-mode git-commit magit-git magit-section magit-utils ido crm
magit-popup log-edit message rfc822 mml mml-sec epa epg gnus-util rmail
rmail-loaddefs mailabbrev gmm-utils mailheader pcvs-util add-log
with-editor term ehelp esh-var esh-cmd esh-opt esh-io esh-ext esh-proc
esh-arg esh-groups eshell esh-module esh-mode async-bytecomp async
server imenu undo-tree diff edebug network-stream puny nsm rmc
company-jedi jedi-core epc ctable concurrent cap-words superword subword
pipenv f eieio-opt speedbar sb-image ezimage dframe warnings pulse
cl-print debug vc-git diff-mode bookmark pp company-elisp nameless
guide-key popwin face-remap disp-table whitespace flycheck find-func rx
jka-compr let-alist colir mmr-org-settings python tramp-sh tramp
trampver tramp-compat tramp-loaddefs ucs-normalize shell pcomplete
parse-time format-spec counsel-projectile projectile skeleton ibuf-macs
wgrep grep ibuf-ext ibuffer ibuffer-loaddefs counsel dired
dired-loaddefs compile esh-util swiper ivy-rich ivy delsel ivy-overlay
ffap thingatpt traad virtualenvwrapper gud comint ansi-color s
request-deferred request mail-utils url url-proxy url-privacy url-expand
url-methods url-history url-cookie url-domsuf url-util mailcap popup
python-environment deferred subr-x company-oddmuse company-keywords
company-etags etags xref project company-gtags company-dabbrev-code
company-dabbrev company-files company-capf company-cmake company-xcode
company-clang company-semantic company-eclim company-template
company-css company-nxml company-bbdb company pyvenv paredit
auto-compile packed recentf tree-widget wid-edit yasnippet derived
elec-pair saveplace hydra ring lv paren solarized-dark-theme
solarized-theme solarized color dash display-line-numbers
mmr-dir-local-env mmr-bootstrap quelpa-use-package cl-extra advice pcase
quelpa mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
mm-util ietf-drums mail-prsvr help-fns radix-tree help-mode
package-recipe-mode edmacro kmacro package-build-badges package-build
lisp-mnt use-package use-package-ensure use-package-delight
use-package-diminish use-package-bind-key use-package-core bind-key
diminish cl linum-ex bar-cursor easy-mmode mmr-minimal mmr-ediff
windmove time-date mule-util info finder-inf package easymenu epg-config
url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map url-vars seq byte-opt gv bytecomp
byte-compile cconv cl-loaddefs cl-lib tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 1357726 145867)
 (symbols 48 50837 2)
 (miscs 40 6306 4056)
 (strings 32 121140 10207)
 (string-bytes 1 4278168)
 (vectors 16 68224)
 (vector-slots 8 1809895 106986)
 (floats 8 422 1779)
 (intervals 56 116849 2490)
 (buffers 992 53)
 (heap 1024 76825 5884))