-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Adding new util function for topics validations #495
Conversation
Leaving the `validateTopics` topics function as it is because I believe it is meant for validating the topics coming from the `send()` function. Not sure, though. `validateCreateTopics` contains following checks which are similar to what is been done for Kafka here [https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/common/Topic.scala] - check if the topic is empty. - check if the topic is . or .. - check if the topic length is greater than 249 characters. - check if the topic, is not ASCII alphanumeric.
For build fix.
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.
Looks good to me other than the items mentioned. Thanks again for your contribution!
throw new InvalidConfigError('topic name cannot be . or ..'); | ||
} | ||
if (topic.length > allowedTopicLength) { | ||
throw new InvalidConfigError('topic name is illegal, cannot be longer than ' + allowedTopicLength + ' characters'); |
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.
Do you mind changing to a template literal? We support node 4 now.
|
||
function validateConfig (property, value) { | ||
if (!legalChars.test(value)) { | ||
throw new InvalidConfigError([property, value, "is illegal, contains a character other than ASCII alphanumerics, '.', '_' and '-'"].join(' ')); | ||
} | ||
} | ||
|
||
function validateCreateTopics (topics) { |
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.
Maybe rename this to validateTopicNames
since this isn't specific to just creating topics but we can reuse this to validate topics in the other classes.
@@ -1,13 +1,34 @@ | |||
var assert = require('assert'); | |||
var InvalidConfigError = require('./errors/InvalidConfigError'); | |||
var legalChars = new RegExp('^[a-zA-Z0-9._-]*$'); | |||
var allowedTopicLength = 249; |
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.
const
?
throw new InvalidConfigError('topic name is illegal, cannot be longer than ' + allowedTopicLength + ' characters'); | ||
} | ||
if (!legalChars.test(topic)) { | ||
throw new InvalidConfigError('topic name ' + topic + 'is illegal, contains a character other than ASCII alphanumerics .,_ and -'); |
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.
template literal here as well.
Fixes as per suggestion.
Done with the changes. |
Leaving the
validateTopics
topics function as it is because I believe it is meant for validating the topics coming from thesend()
function. Not sure, though.validateCreateTopics
contains following checks which are similar to what is been done for Kafka here [https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/common/Topic.scala]