Modify

Opened 11 years ago

Last modified 7 years ago

#11119 new enhancement

Strip whitespace from macro arguments

Reported by: Ryan J Ollos Owned by:
Priority: normal Component: AccountManagerPlugin
Severity: normal Keywords: macro argument
Cc: osimons, Jun Omae Trac Release: 0.11

Description (last modified by Ryan J Ollos)

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,

Account Name Email Last Login
admin
user1 User One user1@gmail.com 16 hours ago
user2 User Two user2@gmail.com

Attachments (0)

Change History (5)

comment:1 Changed 11 years ago by Ryan J Ollos

Description: modified (diff)

comment:2 Changed 11 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 Changed 11 years ago by Steffen Hoffmann

Cc: osimons Jun Omae added; anonymous removed
Keywords: macro argument added
Trac Release: 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 11 years ago by Ryan J Ollos

Replying to hasienda:

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 years ago by Ryan J Ollos

Owner: Steffen Hoffmann deleted

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.