-
Notifications
You must be signed in to change notification settings - Fork 151
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
Check for subject and queue name validity #279
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -648,6 +648,50 @@ public long Dropped | |||||
} | ||||||
} | ||||||
|
||||||
#region validation | ||||||
|
||||||
static private readonly char[] invalidSubjectChars = { '\r', '\n', '\t', ' '}; | ||||||
|
||||||
private static bool IsValidTokenOrQName(string value) | ||||||
{ | ||||||
return (!string.IsNullOrEmpty(value) && value.LastIndexOfAny(invalidSubjectChars) < 0); | ||||||
} | ||||||
|
||||||
/// <summary> | ||||||
/// Checks if a subject is valid. | ||||||
/// </summary> | ||||||
/// <param name="subject">The subject to check</param> | ||||||
/// <returns>true if valid, false otherwise.</returns> | ||||||
static public bool IsValidSubject(string subject) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||||||
{ | ||||||
if (!IsValidTokenOrQName(subject)) | ||||||
{ | ||||||
return false; | ||||||
} | ||||||
|
||||||
string[] tokens = subject.Split('.'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is ever on the hot path (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a comment. |
||||||
foreach (string t in tokens) | ||||||
{ | ||||||
if (t.Length == 0) | ||||||
{ | ||||||
return false; | ||||||
} | ||||||
} | ||||||
return true; | ||||||
} | ||||||
|
||||||
/// <summary> | ||||||
/// Checks if the queue group name is valid. | ||||||
/// </summary> | ||||||
/// <param name="queueGroup"></param> | ||||||
/// <returns>true is the queue group name is valid, false otherwise.</returns> | ||||||
static public bool IsValidQueueGroupName(string queueGroup) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||||||
{ | ||||||
return IsValidTokenOrQName(queueGroup); | ||||||
} | ||||||
|
||||||
#endregion | ||||||
|
||||||
} // Subscription | ||||||
|
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if
LastIndexOfAny
has received the perf improvements thatIndexOfAny
has as of .NET Core.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thanks!