-
Notifications
You must be signed in to change notification settings - Fork 50
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
Protect board and card name when building prefix-log. #384
Conversation
Replace percent (%) sign in board or card names to avoid error message when `orgtrello-log-msg` is called.
1 similar comment
Hello, nice catch. That sounds more like a behavior to fix in the Possible implementation:
Either way, we would then deal for all actual org-trello log messages. Also, that possibly is simpler to capture in tests as it centralizes that behavior to check for that particular function. As a workflow, i'd probably do something:
As to implementation, that would possibly be around either error handling or throw/catch functions, as demo below (without actually testing it works though): Actual code (org-trello-log.el file): (defun orgtrello-log-msg (level &rest args)
"Log message with LEVEL.
Depending on `orgtrello-log-level', this will be displayed or not.
All errors are displayed anyway.
ARGS constitutes the parameters to feed to message."
(when (or (<= level orgtrello-log-level) (eq orgtrello-log-error level))
(apply 'message (format "org-trello - %s" (car args)) (cdr args)))) could possibly be improved to: (defun orgtrello-log--sanitize-input (arg)
"Sanitize input by protecting against specific character in ARG.
Basic implementation, we could actually check the symbol exists
in it.
ARG constitutes the arg to sanitize, could be anything loggable.
"
(if (stringp arg)
(replace-regexp-in-string "%" "%%" arg)
arg))
;; 1st version
(defun orgtrello-log-msg-1 (level &rest args)
"Log message with LEVEL.
Depending on `orgtrello-log-level', this will be displayed or not.
All errors are displayed anyway.
ARGS constitutes the parameters to feed to message."
(-let ((_args (mapcar orgtrello-log--sanitize-input args)))
(when (or (<= level orgtrello-log-level) (eq orgtrello-log-error level))
(apply 'message (format "org-trello - %s" (car args)) (cdr args)))))
;; 2nd version
(defun orgtrello-log-msg (level &rest args)
"Log message with LEVEL.
Depending on `orgtrello-log-level', this will be displayed or not.
All errors are displayed anyway.
ARGS constitutes the parameters to feed to message."
(when (or (<= level orgtrello-log-level) (eq orgtrello-log-error level))
(condition-case nil
(apply 'message (format "org-trello - %s" (car _args)) (cdr _args))
(error
(let ((args (mapcar orgtrello-log--sanitize-input args)))
(apply 'message (format "org-trello - %s" (car args)) (cdr args))))))) Note: again, not tested, only linted ;) What do you think? Cheers, |
Hello @ardumont,
So I tried to send "good" informations to |
Right.
That's unexpected! I did not get why those calls failed but the (message "Hi there ! you've done 95% of the work")
;; raise Debugger entered--Lisp error: (error "Not enough arguments for format string") So, that made me adapt slightly my proposal. (defun orgtrello-log--sanitize-input (arg)
"Sanitize input by protecting against specific character in ARG.
Basic implementation, we could actually check the symbol exists
in it.
ARG constitutes the arg to sanitize, should something loggable."
(if (stringp arg)
(replace-regexp-in-string "% " "%% " arg) ;; I changed the regexp to only apply on '%' followed by a space.
arg))
(defun orgtrello-log-msg-1 (level &rest args)
"Log message with LEVEL.
Depending on `orgtrello-log-level', this will be displayed or not.
All errors are displayed anyway.
ARGS constitutes the parameters to feed to message."
(when (or (<= level orgtrello-log-level) (eq orgtrello-log-error level))
(condition-case nil
(apply 'message (format "org-trello - %s" (car args)) (cdr args))
(error
(let ((args (mapcar 'orgtrello-log--sanitize-input args)))
(apply 'message (format "org-trello - %s" (car args)) (cdr args)))))))
(defun orgtrello-log-msg-2 (level &rest args)
"Log message with LEVEL.
Depending on `orgtrello-log-level', this will be displayed or not.
All errors are displayed anyway.
ARGS constitutes the parameters to feed to message."
(when (or (<= level orgtrello-log-level) (eq orgtrello-log-error level))
(let ((args (mapcar 'orgtrello-log--sanitize-input args)))
(apply 'message (format "org-trello - %s" (car args)) (cdr args)))))
;; those actually works now so \m/
(orgtrello-log-msg-1 orgtrello-log-info "done 95% of work")
(orgtrello-log-msg-1 orgtrello-log-info "Hi there at %s" (format-time-string "%Y/%m/%d %H:%M:%S"))
(orgtrello-log-msg-1 orgtrello-log-info "Hi there ! you've done 95% of the work" )
(orgtrello-log-msg-2 orgtrello-log-info "Hi there ! you've done 95% of the work at %s" (format-time-string "%Y/%m/%d %H:%M:%S"))
(orgtrello-log-msg-2 orgtrello-log-info "done 95% of work")
(orgtrello-log-msg-2 orgtrello-log-info "Hi there at %s" (format-time-string "%Y/%m/%d %H:%M:%S"))
(orgtrello-log-msg-2 orgtrello-log-info "Hi there ! you've done 95% of the work" )
(orgtrello-log-msg-2 orgtrello-log-info "Hi there ! you've done 95% of the work at %s" (format-time-string "%Y/%m/%d %H:%M:%S")) What do you think? I prefer version orgtrello-message-2 (which evaluates args only when the log level is correct, it's better than the proposed 2's first version which evaluated even when not needed). Cheers, |
Looks better, but I don't know if you looked at Percent sign. There is one language (Hebrew) where the percent sign precede the number and without a space ... |
Oh, Interesting, thanks for sharing!
That sounds reasonable. After all, I don't intend to translate in hebrew (not even in my language really ;).
Well, both version, it's just 2 is more concise and looks more -- So, how do you want to proceed, if at all?
Either way sounds good to me ;) Thanks for your time. Cheers, |
I think it's more your solution than my PR now :-) |
I believe it's a joint effort ;)
Ok, done. Thanks for raising this up! |
Replace the percent sign (%) in the names of cards or cards to avoid an error message when
orgtrello-log-msg
is called.I started
make test
and all the tests are correct, but I did not find how to add new ones for the current case.ex:
prepare a card with text as below
try adding a comment with
C-c o C
, type some text and validate withC-c C-c
You have the following error message:
` org-trello - Add a comment on the card '5abac66544c84eb1a898082e' ... FAILED. Error: ("Not enough arguments for format string" error)
`This patch corrects this behavior.