# HG changeset patch # User Markus Mützel # Date 1608575098 -3600 # Node ID 45abff4199d8dbab0574231ad36eee17b12f0b0a # Parent e8819aa30715582e62608ad588757624dcda2935 stat: Improve regular expression for UNC roots on Windows (bug #59706). * liboctave/system/file-stat.cc (file_stat::update_internal): Improve regular expression for UNC roots on Windows. Add simple checks to avoid using the regular expression for non-UNC paths. diff -r e8819aa30715 -r 45abff4199d8 liboctave/system/file-stat.cc --- a/liboctave/system/file-stat.cc Mon Dec 21 11:29:35 2020 +0100 +++ b/liboctave/system/file-stat.cc Mon Dec 21 19:24:58 2020 +0100 @@ -204,11 +204,13 @@ // If path is a root (like "C:" or "\\SERVER\share"), add a // trailing backslash. - // FIXME: Does this pattern match all possible UNC roots? - regexp pat (R"(^\\\\[\w-]*\\[\w-]*$)"); + // FIXME: This pattern does not match all possible UNC roots: + // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/62e862f4-2a51-452e-8eeb-dc4ff5ee33cc + regexp pat (R"(^\\\\[\w.-]+\\[\w\$-]+$)"); if ((full_file_name.length () == 2 && full_file_name[1] == ':') - || pat.is_match (full_file_name)) - full_file_name += '\\'; + || (full_file_name.length () > 4 && full_file_name[0] == '\\' + && full_file_name[1] == '\\' && pat.is_match (full_file_name))) + full_file_name.push_back ('\\'); #endif const char *cname = full_file_name.c_str ();