Argument of \bbl@tempd has an extra }

This only throws the error when running it with TexLive 2017 on Debian 9. If I run the same example on Windows 10 with MikTex, everything works fine:

\PassOptionsToPackage{main=brazil,english,spanish,french}{babel}
\documentclass[brazilian,brazil,10pt,a4paper,]{memoir}

\usepackage{babel}
\usepackage{hyperref}

\newcommand{\autor}[1]{\author{#1}}
\newcommand{\imprimirautor}{\theauthor}
\newcommand{\brazilword}[1]{\foreignlanguage{brazil}{#1}}

\hypersetup{
pdfauthor={\imprimirautor},
}

\begin{document}
Hi.
\end{document}

(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty)))
! Argument of \bbl@tempd has an extra }.
<inserted text>
\par
l.14 }

? H
I've run across a }' that doesn't seem to match anything.
For example, \def\a#1{...}' and \a}' would produce
this error. If you simply proceed now, the \par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your }' was spurious, just type 2' and it will go away.

• Your example does not work fine with miktex: check the author in the pdf properties, you will see the word "brazil" there. Adding \protect helps, but in general it is not a good idea to add lots of complicated commands like \foreignlanguage to stuff that should end in the pdf booksmarks or info dictionary. – Ulrike Fischer Oct 21 '19 at 9:16
• @UlrikeFischer, MikTex should throw an error as TexLive does at least. – user Oct 21 '19 at 17:26
• a current texlive doesn't give an error either. – Ulrike Fischer Oct 21 '19 at 17:33

After looking over the code, I found that adding \protect before the \foreignlanguage babel command, fixed it for TexLive 2017 and MikTeX. The only question is why it worked correctly before for MikTeX without "protection" while it throw errors for TexLive.