Skip to content

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

Open

Description

@AljenU

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)

Activity

  1. AljenU commented on Nov 8, 2021

    @AljenU
    CollaboratorAuthor

    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.

  2. added a commit that references this issue on Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions