Subject: bug#50202: bibtex-mode: unescaped dollar sign in file field leads to wrong highlighting

From: Yuu Yin <[email-masked]>
Date: Wed, 25 Aug 2021 17:48:39 +0000

** Expected behavior
Given a buffer with

- bibtex-mode enabled,
- and a BibTeX entry which has a file field that in turn has as value a path that has a dollar sign ~/path/to/file $ name.ext~,

bibtex-mode correctly highlights this entry and following BibTeX entries in the buffer considering that the file field is a verbatim field (https://github.com/retorquere/zotero-better-bibtex/issues/1895#issuecomment-905572487).

** Actual behavior
Given a buffer with

- bibtex-mode enabled,
- and a BibTeX entry which has as value for file field a path that has dollar sign ~/path/to/file $ name.ext~

bibtex-mode doesn't recognizes that the dollar sign is verbatim for the file field, leading to wrong highlighting.

** Reproduce
1. Open buffer with bibtex-mode enabled
2. Add to the buffer the following content

#+begin_src bibtex
@book{test-2021-test,
title = {Test},
author = {{Test}},
year = {2021},
f file = {/tmp/test \$ test.epub}
}

@book{test-2021-test,
title = {Test},
author = {{Test}},
year = {2021},
file = {/tmp/test $ test.epub}
}

@book{test-2021-test,
title = {Test},
author = {{Test}},
year = {2021},
file = {/tmp/test $ test.epub}
}
#+end_src

See that in the first entry the escaped dollar sign leads to correct highlight, but in the second entry the unescaped dollar sign leads to wrong highlighting.

In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.16.0)
Repository revision: 7640f1da0be206a7598c96acdfdaaf390a2b546c
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: NixOS 21.11 (Porcupine)

Configured using:
'configure
--prefix=/nix/store/7gspx8jnx0s4wy753rcnfncvwhn5bnfr-emacs-gcc-20210731.0
--disable-build-details --with-modules --with-x-toolkit=gtk3 --with-xft
--with-cairo --with-native-compilation'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix

Major mode: BibTeX

Minor modes in effect:
text-scale-mode: t
tooltip-mode: t
global-eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
indent-tabs-mode: t
transient-mark-mode: t

Load-path shadows:
/run/current-system/sw/share/emacs/site-lisp/site-start hides /nix/store/7gspx8jnx0s4wy753rcnfncvwhn5bnfr-emacs-gcc-20210731.0/share/emacs/site-lisp/site-start

Features:
(shadow sort mail-extr mule-util ispell ffap org-element avl-tree
generator ol-eww eww xdg url-queue thingatpt mm-url ol-rmail ol-mhe
ol-irc ol-info ol-gnus nnselect gnus-search eieio-opt speedbar ezimage
dframe gnus-art mm-uu mml2015 mm-view mml-smime smime dig gnus-sum shr
kinsoku svg dom browse-url url url-proxy url-privacy url-expand
url-methods url-history url-cookie url-domsuf url-util url-parse
url-vars mailcap gnus-group gnus-undo gnus-start gnus-dbus dbus xml
gnus-cloud nnimap nnmail mail-source utf7 netrc nnoo parse-time
gnus-spec gnus-int gnus-range gnus-win gnus nnheader wid-edit ol-docview
doc-view jka-compr image-mode exif ol-bibtex ol-bbdb ol-w3m org ob
ob-tangle ob-ref ob-lob ob-table ob-exp org-macro org-footnote org-src
ob-comint org-pcomplete pcomplete comint ansi-color ring org-list
org-faces org-entities noutline outline easy-mmode org-version
ob-emacs-lisp ob-core ob-eval org-table ol org-keys org-compat advice
org-macs org-loaddefs format-spec find-func cal-menu calendar
cal-loaddefs emacsbug message rmc puny dired dired-loaddefs rfc822 mml
mml-sec epa derived epg epg-config gnus-util rmail rmail-loaddefs
auth-source eieio eieio-core eieio-loaddefs password-cache json map
text-property-search mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils face-remap bibtex iso8601 time-date server
comp comp-cstr warnings subr-x rx cl-seq cl-macs cl-extra help-mode seq
byte-opt gv cl-loaddefs cl-lib bytecomp byte-compile cconv iso-transl
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 tab-bar menu-bar rfn-eshadow isearch
easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer 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
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 262122 31074)
(symbols 48 20673 0)
(strings 32 73673 3641)
(string-bytes 1 2487919)
(vectors 16 38674)
(vector-slots 8 687588 32704)
(floats 8 325 267)
(intervals 56 1287 404)
(buffers 992 16))