Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AljenU opened this issue Nov 5, 2021 · 1 comment
Labels

Comments

@AljenU
Copy link
Collaborator

AljenU commented Nov 5, 2021

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 AljenU added the bug label Nov 5, 2021
@AljenU
Copy link
Collaborator Author

AljenU commented Nov 8, 2021

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 added a commit to AljenU/automaticanalysis that referenced this issue Nov 10, 2021
Escape backslash characters in the windows paths, to prevent them from being interpreted as special character identifiers in printf functions

Fixes for issue automaticanalysis#276
AljenU added a commit to AljenU/automaticanalysis that referenced this issue Dec 16, 2021
Escape backslash characters in the windows paths, to prevent them from being
interpreted as special character identifiers in printf functions

Partial fix for issue automaticanalysis#276
AljenU added a commit to AljenU/automaticanalysis that referenced this issue Dec 16, 2021
Escape backslash characters in possible windows paths, to prevent them from being
interpreted as special character identifiers in printf functions

Partial fix for issue automaticanalysis#276
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant