[api/silenced] allow for subscriptions containing colons *and* hyphens #1457
Conversation
@@ -3,7 +3,7 @@ module API | |||
module Routes | |||
module Silenced | |||
SILENCED_URI = /^\/silenced$/ | |||
SILENCED_SUBSCRIPTION_URI = /^\/silenced\/subscriptions\/([\w\.-:]+)$/ | |||
SILENCED_SUBSCRIPTION_URI = /^\/silenced\/subscriptions\/([\w\.:-]+)$/ |
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.
It's traditional to put a - first in a character class. Or \escape it.
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'll escape it for clarity. 👍
…criptions Some of the test assertions already committed weren't running because they were not nested within a single block and async_done was being called too early. This change ensures those assertions run, removes some assertions that aren't particularly relevant to this test, and creates test examples for a variety of subscription names using colons, hyphens and underscores to exercise the regexp used by the /silenced/subscriptions/:subscription API endpoint.
…RI regexps I think we should escape the hyphen here for purposes of indicating that we want to match a hyphen and not to indicate a range.
"load-balancer", | ||
"load_balancer", | ||
"loadbalancer" | ||
].each do |sub| |
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.
The only criticism that I have for you, why not subscription
? We've avoided the use of short and single character variables when possible.
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.
Other then changing this variable, 👍
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.
Fixed ✅
@portertech ready for merge |
Description
In #1450 we introduced a change to the regexp for validating requests to the
/silenced/subscriptions/:subscription
endpoint, but this change introduced a regression preventing the handling of subscriptions that also contain a hyphen (e.g. HTTP GET against/silenced/subscriptions/client:foo
works but HTTP GET agains/silenced/subscriptions/client:foo-bar
does not).Transposing the positions of-
and:
in the regex seems to solve the problem.In the interests of clarity and readability I've opted to escape the hyphen rather than change its position.
Related Issue
Closes #1449
Motivation and Context
The regexp for matching valid subscriptions under /silenced/subscriptions route
excludes valid subscriptions containing colons and hyphens, e.g.
client:foo-bar
.How Has This Been Tested?
Expanded the unit test coverage to test a variety of subscriptions using colons, hyphens and underscores in various combinations.
Types of changes
Checklist: