automaticanalysis icon indicating copy to clipboard operation
automaticanalysis copied to clipboard

BUG - (Windows) Feeding aas_log a message with a full path can give unreadable output

Open AljenU opened this issue 3 years ago • 1 comments

On windows, paths can have a \ in them. However, aas_log uses printf functions during logging, with the input message as format specifier. In printf functions, a \ is the start of a special operator. Thus each time such a character is encountered, the printf function will either say that it does not recognize the operator, or print a message with unexpected formatting (i.e. it may have returned to the start of the line halfway into the message)

To prevent this, when a path is part of the message to aas_log, any \ characters should be escaped by doubling them, before sending the message to aas_log.

The replacement cannot be done inside aas_log on the incoming message, as some messages do use valid print formatting, e.g. they use \n to have a newline in the message.

Example fix: Old situation

            msg = sprintf('Done: %s for %s \n', description, unsafe_path);
            aas_log(aap, false, msg)

Replace with:

            % When used in aas_log messages, escape backward slashes from
            % windows paths.
            logsafe_path = strrep(unsafe_path, '\', '\\');
            msg = sprintf('Done: %s for %s \n', description, logsafe_path);
            aas_log(aap, false, msg)

AljenU avatar Nov 05 '21 13:11 AljenU

A common case where this happens, is when one of the first two outputs of aas_doneflag_getpath_bydomain is used in a aas_log message.

AljenU avatar Nov 08 '21 12:11 AljenU