From 6de64667bc84e118dfde6fdbcefcae36fb521b15 Mon Sep 17 00:00:00 2001 From: Todd Beets Date: Mon, 18 Jul 2022 14:20:10 -0700 Subject: [PATCH] follow convention (_EMPTY_, fwcs). Add special case short-circuit to skip unnecessary tokenization and transform. --- server/accounts.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/accounts.go b/server/accounts.go index 9fa71392..e9a814f8 100644 --- a/server/accounts.go +++ b/server/accounts.go @@ -4315,6 +4315,12 @@ func newTransform(src, dest string) (*transform, error) { func (tr *transform) Match(subject string) (string, error) { // TODO(dlc) - We could add in client here to allow for things like foo -> foo.$ACCOUNT + // Special case: matches any and no no-op transform. May not be legal config for some features + // but specific validations made at transform create time + if (tr.src == fwcs || tr.src == _EMPTY_) && (tr.dest == fwcs || tr.dest == _EMPTY_) { + return subject, nil + } + // Tokenize the subject. This should always be a literal subject. tsa := [32]string{} tts := tsa[:0] @@ -4330,7 +4336,7 @@ func (tr *transform) Match(subject string) (string, error) { return _EMPTY_, ErrBadSubject } - if (tr.src == "" || tr.src == ">") || isSubsetMatch(tts, tr.src) { + if (tr.src == _EMPTY_ || tr.src == fwcs) || isSubsetMatch(tts, tr.src) { return tr.transform(tts) } return _EMPTY_, ErrNoTransforms