Opened 4 years ago

# Strip whitespace from macro arguments

Reported by: Owned by: Ryan J Ollos normal AccountManagerPlugin normal macro argument Odd Simon Simonsen, Jun Omae 0.11

While working on a patch t:#10751, I added a stripws argument to parse_args, to strip leading and trailing whitespace from macro arguments (see cd5f4cee). There hasn't been any interest expressed in the patch so far, but I encountered a situation this evening that made me think we should deal with this directly in the UserStats macro.

The macro call [[UserQuery(email, name, visit)]] results in the list [u'email', u' name', u' visit']. The output of the macro is then,

admin, user1 <user1@gmail.com>, user2 <user2@gmail.com>


rather than the expected,

user1 User One user1@gmail.com 16 hours ago
user2 User Two user2@gmail.com

### comment:1 Changed 4 years ago by Ryan J Ollos

Description: modified (diff)

### comment:2 Changed 4 years ago by Ryan J Ollos

Here is what I have in mind: Implement a _parse_args function in acctmgr.macros that calls trac.wiki.api.parse_args and strips whitespace from the parameters. That way it will be easy to write a test case and the function can be reused if we end up with multiple classes in acct_mgr.macros later on.

### comment:3 follow-up:  4 Changed 4 years ago by Steffen Hoffmann

Cc: Odd Simon Simonsen Jun Omae added; anonymous removed macro argument added → 0.11

Sure, but I really wonder, why parse_args does not behave like that in the first place.

Something like parse_args(content, strip=true) comes in mind, if it should not be desired as default for whatever reason. I just can't think of a valid one right now, anyone else?

### comment:4 in reply to:  3 Changed 4 years ago by Ryan J Ollos

Sure, but I really wonder, why parse_args does not behave like that in the first place.

Same thoughts here. In the patch for Trac, I set the default to stripws=False for backward compatibility, but backward-compatibility considerations aside, I think stripws=True is a better default.

Most of the macros in Trac end up stripping whitespace after parse_args is called, for example TracIni macro.

### comment:5 Changed 7 months ago by Ryan J Ollos

Owner: Steffen Hoffmann deleted

### Modify Ticket

Change Properties